awslabs / amazon-dynamodb-lock-client

The AmazonDynamoDBLockClient is a general purpose distributed locking library built on top of DynamoDB. It supports both coarse-grained and fine-grained locking.
Other
472 stars 85 forks source link

Support querying all locks with the same partition key #58

Open lcabancla opened 3 years ago

lcabancla commented 3 years ago

Support querying all locks with the same partition key.

The function signature can be similar to:

    /**
     * <p>
     * Retrieves the locks with partition_key = {@code key}.
     * </p>
     * <p>
     * Not that this may return a lock item even if it was released.
     * </p>
     *
     * @param key the partition key
     * @param deleteOnRelease Whether or not the {@link LockItem} should delete the item
     *                        when {@link LockItem#close()} is called on it.
     * @return A non parallel {@link Stream} of {@link LockItem}s that has the partition key in
     * DynamoDB. Note that the item can exist in the table even if it is
     * released, as noted by {@link LockItem#isReleased()}.
     */
    public Stream<LockItem> getLocksByPartitionKey(String key, final boolean deleteOnRelease) {

Currently the only way to get multiple leases is by scanning the table ie - via getAllLocksFromDynamoDB(). This is useful in cases where we only want to query a subset of the leases. For example, leases can be categorized and each lease in the same category has the same partition key but different sort keys.

Loading all leases by partition key should require an efficient query instead of a full scan.