Skip to content

Commit

Permalink
Add support for "vshard_router" option
Browse files Browse the repository at this point in the history
Closes #463
  • Loading branch information
nickkkccc committed Jan 19, 2024
1 parent 14e051a commit 6f27b3e
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;

/**
* Marker interface for space delete operation options
Expand All @@ -11,5 +12,6 @@
* @author Alexey Kuzin
*/
public interface DeleteOptions<T extends DeleteOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithRollbackOnErrorOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithStopOnErrorOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;

/**
* Marker interface for space insert_many operation options
Expand All @@ -12,5 +13,5 @@
*/
public interface InsertManyOptions<T extends InsertManyOptions<T>>
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>, OperationWithRollbackOnErrorOptions<T>,
OperationWithStopOnErrorOptions<T> {
OperationWithStopOnErrorOptions<T>, OperationWithVshardRouterOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;

/**
* Marker interface for space insert operation options
Expand All @@ -11,5 +12,6 @@
* @author Alexey Kuzin
*/
public interface InsertOptions<T extends InsertOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithRollbackOnErrorOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithStopOnErrorOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;

/**
* Marker interface for space replace_many operation options
Expand All @@ -12,5 +13,5 @@
*/
public interface ReplaceManyOptions<T extends ReplaceManyOptions<T>>
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>, OperationWithRollbackOnErrorOptions<T>,
OperationWithStopOnErrorOptions<T> {
OperationWithStopOnErrorOptions<T>, OperationWithVshardRouterOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;

/**
* Marker interface for space replace operation options
Expand All @@ -11,5 +12,6 @@
* @author Alexey Kuzin
*/
public interface ReplaceOptions<T extends ReplaceOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithModeOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;

/**
* Marker interface for space select operation options
Expand All @@ -16,5 +17,5 @@
*/
public interface SelectOptions<T extends SelectOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithModeOptions<T>, OperationWithBatchSizeOptions<T> {
OperationWithModeOptions<T>, OperationWithBatchSizeOptions<T>, OperationWithVshardRouterOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;

/**
* Marker interface for space update operation options
Expand All @@ -11,5 +12,6 @@
* @author Alexey Kuzin
*/
public interface UpdateOptions<T extends UpdateOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;

/**
* Marker interface for space upsert operation options
Expand All @@ -11,5 +12,6 @@
* @author Alexey Kuzin
*/
public interface UpsertOptions<T extends UpsertOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T> {
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.tarantool.driver.api.space.options.crud;

import java.util.Optional;

import io.tarantool.driver.api.space.options.Options;
import io.tarantool.driver.api.space.options.Self;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;

/**
* Base interface for all operation options that may have a configurable "vshard_router" value.
*/
public interface OperationWithVshardRouterOptions<T extends OperationWithVshardRouterOptions<T>>
extends Options, Self<T> {

/**
* Sets "vshard_router" option value. Cartridge vshard group name or vshard router instance. Set this parameter
* if your space is not a part of the default vshard cluster.
*
* @param vshardRouter cartridge vshard group name or vshard router instance. Set this parameter if your space
* is not a part of the default vshard cluster.
* @return this options instance.
* @throws IllegalArgumentException if vshardRouter is null or consists only of spaces.
*/
default T withVshardRouter(String vshardRouter) throws IllegalArgumentException {
if (vshardRouter.trim().isEmpty()) {
throw new IllegalArgumentException("\"vshardRouter\" parameter cannot be empty or consist only of spaces.");
}
addOption(ProxyOption.VSHARD_ROUTER, vshardRouter);
return self();
}

/**
* @return "vshard_router" option value.
*/
default Optional<String> getVshardRouter() {
return getOption(ProxyOption.VSHARD_ROUTER, String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public enum ProxyOption {

AFTER("after"),

FIRST("first");
FIRST("first"),

VSHARD_ROUTER("vshard_router");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.tarantool.driver.api.space.options.ProxyDeleteOptions;
import io.tarantool.driver.api.space.options.ProxyInsertOptions;
import io.tarantool.driver.api.space.options.DeleteOptions;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;
import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.api.tuple.TarantoolTupleFactory;
Expand Down Expand Up @@ -161,4 +162,25 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(1, tuple.getInteger(0));
assertEquals("FIO", tuple.getString(1));
}

@Test
public void withVshardRouterTest() {
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace =
client.space(TEST_SPACE_NAME);

TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100);
profileSpace.insert(tarantoolTuple).join();

Conditions conditions = Conditions.equals(PK_FIELD_NAME, 1);
final String groupName = "default";
DeleteOptions<ProxyDeleteOptions> options = ProxyDeleteOptions.create().withVshardRouter(groupName);

TarantoolResult<TarantoolTuple> deleteResult = profileSpace.delete(conditions, options).join();
TarantoolResult<TarantoolTuple> selectResultAfterDelete = profileSpace.select(Conditions.any()).join();
List<?> crudDeleteOpts = client.eval("return crud_delete_opts").join();

assertEquals(groupName, ((HashMap<?, ?>) crudDeleteOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
assertEquals(1, deleteResult.size());
assertEquals(0, selectResultAfterDelete.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.tarantool.driver.api.conditions.Conditions;
import io.tarantool.driver.api.space.TarantoolSpaceOperations;
import io.tarantool.driver.api.space.options.InsertManyOptions;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;
import io.tarantool.driver.api.space.options.crud.enums.RollbackOnError;
import io.tarantool.driver.api.space.options.crud.enums.StopOnError;
import io.tarantool.driver.api.space.options.ProxyInsertManyOptions;
Expand Down Expand Up @@ -188,4 +189,23 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(String.valueOf(i), tuple.getString(1));
}
}

@Test
public void withVshardRouterTest() {
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace =
client.space(TEST_SPACE_NAME);

List<TarantoolTuple> tarantoolTuples = Arrays.asList(
tupleFactory.create(0, null, "0", 0, 0),
tupleFactory.create(1, null, "1", 1, 1));

final String groupName = "default";
InsertManyOptions<ProxyInsertManyOptions> options = ProxyInsertManyOptions.create()
.withVshardRouter(groupName);

TarantoolResult<TarantoolTuple> insertManyResult = profileSpace.insertMany(tarantoolTuples, options).join();
List<?> crudInsertManyOpts = client.eval("return crud_insert_many_opts").join();
assertEquals(2, insertManyResult.size());
assertEquals(groupName, ((HashMap<?, ?>) crudInsertManyOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.tarantool.driver.api.space.options.SelectOptions;
import io.tarantool.driver.api.space.options.ProxyInsertOptions;
import io.tarantool.driver.api.space.options.ProxySelectOptions;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;
import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.api.tuple.TarantoolTupleFactory;
Expand Down Expand Up @@ -267,4 +268,21 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(1, tuple.getInteger(0));
assertEquals("FIO", tuple.getString(1));
}

@Test
public void withVshardRouterTest() {
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace =
client.space(TEST_SPACE_NAME);

TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100);

final String groupName = "default";
InsertOptions<ProxyInsertOptions> options = ProxyInsertOptions.create().withVshardRouter(groupName);

TarantoolResult<TarantoolTuple> insertResult = profileSpace.insert(tarantoolTuple, options).join();
List<?> crudInsertOpts = client.eval("return crud_insert_opts").join();

assertEquals(1, insertResult.size());
assertEquals(groupName, ((HashMap<?, ?>) crudInsertOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.tarantool.driver.api.TarantoolResult;
import io.tarantool.driver.api.space.TarantoolSpaceOperations;
import io.tarantool.driver.api.space.options.ReplaceManyOptions;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;
import io.tarantool.driver.api.space.options.crud.enums.RollbackOnError;
import io.tarantool.driver.api.space.options.crud.enums.StopOnError;
import io.tarantool.driver.api.space.options.ProxyReplaceManyOptions;
Expand Down Expand Up @@ -171,4 +172,24 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(String.valueOf(i), tuple.getString(1));
}
}

@Test
public void withVsharRouterTest() {
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace =
client.space(TEST_SPACE_NAME);

List<TarantoolTuple> tarantoolTuples = Arrays.asList(
tupleFactory.create(0, null, "0", 0, 0),
tupleFactory.create(1, null, "1", 1, 1));

final String groupName = "default";
ReplaceManyOptions<ProxyReplaceManyOptions> options = ProxyReplaceManyOptions.create()
.withVshardRouter(groupName);

TarantoolResult<TarantoolTuple> replaceResult = profileSpace.replaceMany(tarantoolTuples, options).join();
List<?> crudReplaceManyOpts = client.eval("return crud_replace_many_opts").join();

assertEquals(groupName, ((HashMap<?, ?>) crudReplaceManyOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
assertEquals(2, replaceResult.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.tarantool.driver.api.space.options.ReplaceOptions;
import io.tarantool.driver.api.space.options.ProxyDeleteOptions;
import io.tarantool.driver.api.space.options.ProxyReplaceOptions;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;
import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.api.tuple.TarantoolTupleFactory;
Expand Down Expand Up @@ -167,4 +168,21 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(1, tuple.getInteger(0));
assertEquals("FIO", tuple.getString(1));
}

@Test
public void withVsharRouterTest() {
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace =
client.space(TEST_SPACE_NAME);

TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100);

final String groupName = "default";
ReplaceOptions<ProxyReplaceOptions> options = ProxyReplaceOptions.create().withVshardRouter(groupName);

TarantoolResult<TarantoolTuple> replaceResult = profileSpace.replace(tarantoolTuple, options).join();
List<?> crudReplaceOpts = client.eval("return crud_replace_opts").join();

assertEquals(1, replaceResult.size());
assertEquals(groupName, ((HashMap<?, ?>) crudReplaceOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.tarantool.driver.api.space.options.SelectOptions;
import io.tarantool.driver.api.space.TarantoolSpaceOperations;
import io.tarantool.driver.api.space.options.ProxySelectOptions;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;
import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.api.tuple.TarantoolTupleFactory;
Expand Down Expand Up @@ -174,4 +175,19 @@ public void withModeTest() throws ExecutionException, InterruptedException {
crudSelectOpts = client.eval("return crud_select_opts").get();
assertEquals(Mode.WRITE.value(), ((HashMap<?, ?>) crudSelectOpts.get(0)).get("mode"));
}

@Test
public void withVshardRouterTest() {
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> operations =
client.space(TEST_SPACE_NAME);

operations.select(Conditions.any()).join();
List<?> crudSelectOpts = client.eval("return crud_select_opts").join();
assertNull(((HashMap<?, ?>) crudSelectOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));

final String routerName = "default";
operations.select(Conditions.any(), ProxySelectOptions.create().withVshardRouter(routerName)).join();
crudSelectOpts = client.eval("return crud_select_opts").join();
assertEquals(routerName, ((HashMap<?, ?>) crudSelectOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.tarantool.driver.api.space.TarantoolSpaceOperations;
import io.tarantool.driver.api.space.options.UpdateOptions;
import io.tarantool.driver.api.space.options.ProxyUpdateOptions;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;
import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.api.tuple.TarantoolTupleFactory;
Expand Down Expand Up @@ -158,4 +159,25 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(1, tuple.getInteger(0));
assertEquals("FIO", tuple.getString(1));
}

@Test
public void withVshardRouterTest() {
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace =
client.space(TEST_SPACE_NAME);

TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100);
Conditions conditions = Conditions.equals(PK_FIELD_NAME, 1);

final String groupName = "default";
UpdateOptions<ProxyUpdateOptions> options = ProxyUpdateOptions.create().withVshardRouter(groupName);

TarantoolTuple insertTuple = profileSpace.insert(tarantoolTuple).join().get(0);
TarantoolResult<TarantoolTuple> updateResult = profileSpace.update(conditions, insertTuple, options).join();

List<?> crudUpdateOpts = client.eval("return crud_update_opts").join();

assertEquals(1, updateResult.size());
assertEquals(groupName, ((HashMap<?, ?>) crudUpdateOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
}
}

Loading

0 comments on commit 6f27b3e

Please sign in to comment.