Skip to content

Conversation

bevzzz
Copy link
Collaborator

@bevzzz bevzzz commented Aug 20, 2025

This PR adds an option to set default consistency level and/or tenant on a CollectionHandle/-Async. If set, these will be applied to all operations in aggregate, query and data namespaces. See CollectionHandleTest for a list of all affected requests.

Default consistency level / tenant

The API is simple and similar to that in the Python client (examples show consistency level, but it works the same way for tenants):

// Derive a modified collection handle with a different ConsistencyLevel
var things = client.collections.use("Things");
var thingsQuorum = things.withConsistencyLevel(ConsistencyLevel.QUORUM);
var thingsAll = things.withConsistencyLevel(ConsistencyLevel.ALL);

// Or configure it immediately on creation
var thingsOne = client.collections.use("Things",
    with -> with.consistencyLevel(ConsistencyLevel.ONE));

CollectionHandle/-Async can be inspected:

things.consistencyLevel() // returns null
thingsAll.consistencyLevel() // returns ConsistencyLevel.ALL

Default ConsistencyLevel can be overridden for an individual query. For example, this search is done with ConsistencyLevel.ONE.

thingsAll.query.nearObject(
    "test-uuid",
     q -> q.consistencyLevel(ConsistencyLevel.ONE));

To configure both parameters in one go users can call .withDefaults like so:

things.withDefaults(with ->
  .consistencyLevel(ConsistencyLevel.ONE)
  .tenant("john_doe")
);

Tenants API

Updated (and fixed JSON naming) of multi-tenancy configuration components.

client.collections.create("Things", c -> c.multiTenancy(
  mt -> mt.autoTenantCreation(true).autoTenantActivation(false)
));

Calling .multiTenancy will "enable" it. To prevent that behavior users can set mt.enabled(false) explicitly.

Creating, searching, updating, and deleting tenants is supported:

things.tenants.create(Tenant.active("alex"), Tenant.inactive("bert"));

things.tenants.get("bert").status(); // returns TenantStatus.INACTIVE
things.tenants.get("bert").isInactive(); // returns true
things.tenants.activate("bert");

things.tenants.exists("carl"); // returns false

things.tenants.deactivate("alex") ;
things.tenants.offload("alex") ;
things.tenants.delete("alex");
things.tenants.list(); // returns [Tenant(name=bert, status=TenantStatus.ACTIVE)]

Get shards

The get-shards request now includes tenant query parameter if a default one is set on the collection handle.

Copy link

@orca-security-eu orca-security-eu bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

bevzzz added 3 commits August 21, 2025 23:05
Enpoint interface already provides a convenient way to supply query parameters,
so there isn't much value in indirecting this over ContextEndpoint. Furthermore,
the latter's implementation assumes too much knowledge of the internal.rest package.

As for gRPC, ContextRpc had to do type checks, so there's hardly any code savings
that this approach brings. Adding the parameters to the messages 'in place' seems
to me much more straightforward.

Finally, I merged the 3 test classes for data/query/aggregate namespaces into one
because they follow the same structure, so grouping them will benefit the reader.
This method is only used in one place, inlining it makes more sense.
@bevzzz bevzzz marked this pull request as ready for review August 21, 2025 21:31
@bevzzz bevzzz mentioned this pull request Aug 25, 2025
@bevzzz bevzzz merged commit e4d1f90 into v6 Aug 26, 2025
2 checks passed
@bevzzz bevzzz deleted the v6-tenant branch August 26, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants