Skip to content

Commit

Permalink
fix inv and store lock logic
Browse files Browse the repository at this point in the history
  • Loading branch information
terrywbrady committed Aug 16, 2024
1 parent 6dd0f6b commit aafe76b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
13 changes: 7 additions & 6 deletions src/main/java/org/cdlib/mrt/zk/MerrittLocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,23 @@ public static boolean checkLockCollection(ZooKeeper client, String mnemonic) thr
}

public static boolean lockObjectStorage(ZooKeeper client, String ark) {
return createEphemeralLock(client, Paths.get(QueueItem.ZkPaths.LocksStorage.path, ark.replaceAll("\\/", "_")).toString());
return createEphemeralLock(client, Paths.get(QueueItem.ZkPaths.LocksStorage.path, ark.replaceAll(":?/", "_")).toString());
}
public static void unlockObjectStorage(ZooKeeper client, String ark) throws InterruptedException, KeeperException {
QueueItemHelper.delete(client, Paths.get(QueueItem.ZkPaths.LocksStorage.path, ark.replaceAll("\\/", "_")).toString());
QueueItemHelper.delete(client, Paths.get(QueueItem.ZkPaths.LocksStorage.path, ark.replaceAll(":?/", "_")).toString());
}
public static boolean checkLockObjectStorage(ZooKeeper client, String ark) throws KeeperException, InterruptedException {
return QueueItemHelper.exists(client, Paths.get(QueueItem.ZkPaths.LocksStorage.path, ark.replaceAll("\\/", "_")).toString());
System.out.println(client.getChildren(QueueItem.ZkPaths.LocksStorage.path, false));
return QueueItemHelper.exists(client, Paths.get(QueueItem.ZkPaths.LocksStorage.path, ark.replaceAll(":?/", "_")).toString());
}

public static boolean lockObjectInventory(ZooKeeper client, String ark) {
return createEphemeralLock(client, Paths.get(QueueItem.ZkPaths.LocksInventory.path, ark.replaceAll("\\/", "_")).toString());
return createEphemeralLock(client, Paths.get(QueueItem.ZkPaths.LocksInventory.path, ark.replaceAll(":?/", "_")).toString());
}
public static void unlockObjectInventory(ZooKeeper client, String ark) throws InterruptedException, KeeperException {
QueueItemHelper.delete(client, Paths.get(QueueItem.ZkPaths.LocksInventory.path, ark.replaceAll("\\/", "_")).toString());
QueueItemHelper.delete(client, Paths.get(QueueItem.ZkPaths.LocksInventory.path, ark.replaceAll(":?/", "_")).toString());
}
public static boolean checkLockObjectInventory(ZooKeeper client, String ark) throws KeeperException, InterruptedException {
return QueueItemHelper.exists(client, Paths.get(QueueItem.ZkPaths.LocksInventory.path, ark.replaceAll("\\/", "_")).toString());
return QueueItemHelper.exists(client, Paths.get(QueueItem.ZkPaths.LocksInventory.path, ark.replaceAll(":?/", "_")).toString());
}
}
12 changes: 6 additions & 6 deletions src/main/ruby/lib/merritt_zk_locks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,29 @@ def self.unlock_collection(zk, mnemonic)
end

def self.lock_object_storage(zk, ark)
create_ephemeral_lock(zk, "#{LOCKS_STORAGE}/#{ark.gsub('/', '_')}")
create_ephemeral_lock(zk, "#{LOCKS_STORAGE}/#{ark.gsub(':?/', '_')}")
end

def self.check_lock_object_storage(zk, ark)
zk.exists?("#{LOCKS_STORAGE}/#{ark.gsub('/', '_')}")
zk.exists?("#{LOCKS_STORAGE}/#{ark.gsub(':?/', '_')}")
end

def self.unlock_object_storage(zk, ark)
zk.delete("#{LOCKS_STORAGE}/#{ark.gsub('/', '_')}")
zk.delete("#{LOCKS_STORAGE}/#{ark.gsub(':?/', '_')}")
rescue StandardError
# no action
end

def self.lock_object_inventory(zk, ark)
create_ephemeral_lock(zk, "#{LOCKS_INVENTORY}/#{ark.gsub('/', '_')}")
create_ephemeral_lock(zk, "#{LOCKS_INVENTORY}/#{ark.gsub(':?/', '_')}")
end

def self.check_lock_object_inventory(zk, ark)
zk.exists?("#{LOCKS_INVENTORY}/#{ark.gsub('/', '_')}")
zk.exists?("#{LOCKS_INVENTORY}/#{ark.gsub(':?/', '_')}")
end

def self.unlock_object_inventory(zk, ark)
zk.delete("#{LOCKS_INVENTORY}/#{ark.gsub('/', '_')}")
zk.delete("#{LOCKS_INVENTORY}/#{ark.gsub(':?/', '_')}")
rescue StandardError
# no action
end
Expand Down
8 changes: 4 additions & 4 deletions test-cases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,13 @@ lock_collection:
lock_store:
input:
output:
/locks/storage/ark:_aaa_111: null
/locks/storage/ark:_bbb_222: null
/locks/storage/ark_aaa_111: null
/locks/storage/ark_bbb_222: null
lock_inventory:
input:
output:
/locks/inventory/ark:_aaa_111: null
/locks/inventory/ark:_bbb_222: null
/locks/inventory/ark_aaa_111: null
/locks/inventory/ark_bbb_222: null
access_happy_path:
input:
output:
Expand Down

0 comments on commit aafe76b

Please sign in to comment.