Skip to content

Commit

Permalink
fix: admin_getFileLocation; test: sync test (#141)
Browse files Browse the repository at this point in the history
* feat: add all_shards in admin_getFileLocation

* fix: admin_getFileLocation

* test: improve sync test

* fix: lint
  • Loading branch information
MiniFrenchBread authored Jul 23, 2024
1 parent f0c3f2c commit 533bacb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion node/rpc/src/admin/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ impl RpcServer for RpcServerImpl {
tx_seq: u64,
all_shards: bool,
) -> RpcResult<Option<Vec<LocationInfo>>> {
info!("admin_getFileLocation()");

let tx = match self.ctx.log_store.get_tx_by_seq_number(tx_seq).await? {
Some(tx) => tx,
None => {
Expand Down Expand Up @@ -225,7 +227,9 @@ impl RpcServer for RpcServerImpl {
shard_config: shard_config.unwrap(),
})
.collect();
if all_shards && all_shards_available(info.iter().map(|info| info.shard_config).collect()) {

if !all_shards || all_shards_available(info.iter().map(|info| info.shard_config).collect())
{
Ok(Some(info))
} else {
Ok(None)
Expand Down
13 changes: 11 additions & 2 deletions tests/sync_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __test_sync_file_by_rpc(self):
client1 = self.nodes[0]
client2 = self.nodes[1]

# stop client2, preventing it from receiving AnnounceFile
client2.shutdown()

# Create submission
chunk_data = random.randbytes(256 * 1024)
data_root = self.__create_submission(chunk_data)
Expand All @@ -41,16 +44,22 @@ def __test_sync_file_by_rpc(self):
segments = submit_data(client1, chunk_data)
self.log.info("segments: %s", [(s["root"], s["index"], s["proof"]) for s in segments])
wait_until(lambda: client1.zgs_get_file_info(data_root)["finalized"])

# File should not be auto sync on node 2

# restart client2
client2.start()
client2.wait_for_rpc_connection()

# File should not be auto sync on node 2 and there is no cached file locations
wait_until(lambda: client2.zgs_get_file_info(data_root) is not None)
time.sleep(3)
assert_equal(client2.zgs_get_file_info(data_root)["finalized"], False)
assert(client2.admin_get_file_location(0) is None)

# Trigger file sync by rpc
assert(client2.admin_start_sync_file(0) is None)
wait_until(lambda: client2.sync_status_is_completed_or_unknown(0))
wait_until(lambda: client2.zgs_get_file_info(data_root)["finalized"])
assert(client2.admin_get_file_location(0) is not None)

# Validate data
assert_equal(
Expand Down
3 changes: 3 additions & 0 deletions tests/test_framework/zgs_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def admin_get_sync_status(self, tx_seq):
def sync_status_is_completed_or_unknown(self, tx_seq):
status = self.rpc.admin_getSyncStatus([tx_seq])
return status == "Completed" or status == "unknown"

def admin_get_file_location(self, tx_seq, all_shards = True):
return self.rpc.admin_getFileLocation([tx_seq, all_shards])

def clean_data(self):
shutil.rmtree(os.path.join(self.data_dir, "db"))

0 comments on commit 533bacb

Please sign in to comment.