Skip to content

Commit

Permalink
(t) replication spawn error - fix share-name type issue rockstor#2766
Browse files Browse the repository at this point in the history
- minor additional refactoring for clarity.
- keep receiver self.share/snap naming as str, encode before
send only.
- more type-hints.
  • Loading branch information
phillxnet committed Jan 9, 2024
1 parent 89236f6 commit 6a3ea30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/rockstor/smart_manager/replication/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,12 @@ def _send_recv(self, command: bytes, msg: bytes = b""):
logger.debug(f"remote message: {rmsg}")
return rcommand, rmsg

def _latest_snap(self, rso):
def _latest_snap_name(self, rso) -> str | None:
for snap in ReceiveTrail.objects.filter(
rshare=rso, status="succeeded"
).order_by("-id"):
if is_subvol(f"{self.snap_dir}/{snap.snap_name}"):
return str(snap.snap_name).encode(
"utf8"
) # cannot be unicode for zmq message
return str(snap.snap_name)
logger.error(
f"Id: {self.identity}. There are no replication snapshots on the system for Share({rso.share})."
)
Expand Down Expand Up @@ -228,7 +226,7 @@ def run(self):
self.msg = (
b"Failed to verify latest replication snapshot on the system."
)
latest_snap = self._latest_snap(rso)
latest_snap = self._latest_snap_name(rso)

self.msg = f"Failed to create receive trail for rid: {self.rid}".encode(
"utf-8"
Expand Down Expand Up @@ -296,10 +294,11 @@ def run(self):

self.msg = b"Failed to send receiver-ready"
# Previously our second parameter was (latest_snap or b"")
snap = latest_snap
if snap is None:
snap = b"place-holder"
rcommand, rmsg = self._send_recv(b"receiver-ready", snap)
if latest_snap is None:
snap_name = b""
else:
snap_name = latest_snap.encode("utf8")
rcommand, rmsg = self._send_recv(b"receiver-ready", snap_name)
if rcommand == b"":
logger.error(
f"Id: {self.identity}. No response from the broker for receiver-ready command. Aborting."
Expand Down
4 changes: 3 additions & 1 deletion src/rockstor/smart_manager/replication/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@


class Sender(ReplicationMixin, Process):
uuid: str
total_bytes_sent: int
identity: str
rlatest_snap: str | None

def __init__(self, uuid: str, receiver_ip, replica, rt: int | None = None):
self.law = None
Expand Down Expand Up @@ -283,7 +285,7 @@ def run(self):
logger.debug(f"command = {command}, of type {type(command)}")
if command == b"receiver-ready":
if self.rt is not None:
self.rlatest_snap = reply
self.rlatest_snap = reply.decode("utf-8")
self.rt = self._refresh_rt()
logger.debug(
f"Id: {self.identity}. command({command}) and message({reply}) received. Proceeding to send fsdata."
Expand Down

0 comments on commit 6a3ea30

Please sign in to comment.