Skip to content

Commit

Permalink
Add support for "fetch_latest_metadata" option
Browse files Browse the repository at this point in the history
Closes #465
  • Loading branch information
nickkkccc committed Jan 22, 2024
1 parent 14e051a commit 0687238
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.tarantool.driver.api.space.options;

import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;

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>,
OperationWithFetchLatestMetadataOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.tarantool.driver.api.space.options;

import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithRollbackOnErrorOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithStopOnErrorOptions;
Expand All @@ -12,5 +13,5 @@
*/
public interface InsertManyOptions<T extends InsertManyOptions<T>>
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>, OperationWithRollbackOnErrorOptions<T>,
OperationWithStopOnErrorOptions<T> {
OperationWithStopOnErrorOptions<T>, OperationWithFetchLatestMetadataOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.tarantool.driver.api.space.options;

import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;

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>,
OperationWithFetchLatestMetadataOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.tarantool.driver.api.space.options;

import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithRollbackOnErrorOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithStopOnErrorOptions;
Expand All @@ -12,5 +13,5 @@
*/
public interface ReplaceManyOptions<T extends ReplaceManyOptions<T>>
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>, OperationWithRollbackOnErrorOptions<T>,
OperationWithStopOnErrorOptions<T> {
OperationWithStopOnErrorOptions<T>, OperationWithFetchLatestMetadataOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.tarantool.driver.api.space.options;

import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;

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>,
OperationWithFetchLatestMetadataOptions<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.tarantool.driver.api.space.options.crud.OperationWithBatchSizeOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions;
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;
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>, OperationWithFetchLatestMetadataOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.tarantool.driver.api.space.options;

import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;

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>,
OperationWithFetchLatestMetadataOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.tarantool.driver.api.space.options;

import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;

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>,
OperationWithFetchLatestMetadataOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 "fetch_latest_metadata" option.
*
* @author Belonogov Nikolay
*/
public interface OperationWithFetchLatestMetadataOptions<T extends OperationWithFetchLatestMetadataOptions<T>>
extends Options, Self<T> {

/**
* Sets "fetch_latest_metadata" option value to true. Guarantees the up-to-date metadata (space format) in first
* return value, otherwise it may not take into account the latest migration of the data format. Performance
* overhead is up to 15%. False by default.
* @return this options instance.
*/
default T fetchLatestMetadata() {
addOption(ProxyOption.FETCH_LATEST_METADATA, true);
return self();
}

/**
* @return "fetch_latest_metadata" option value.
*/
default Optional<Boolean> getFetchLatestMetadata() {
return getOption(ProxyOption.FETCH_LATEST_METADATA, Boolean.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"),

FETCH_LATEST_METADATA("fetch_latest_metadata");

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 All @@ -30,6 +31,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Artyom Dubinin
Expand Down Expand Up @@ -161,4 +163,26 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(1, tuple.getInteger(0));
assertEquals("FIO", tuple.getString(1));
}

@Test
public void withFetchLatestMetadata() {
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);
DeleteOptions<ProxyDeleteOptions> options = ProxyDeleteOptions.create().fetchLatestMetadata();

assertTrue(options.getFetchLatestMetadata().isPresent());
assertTrue(options.getFetchLatestMetadata().get());

TarantoolResult<TarantoolTuple> deleteResultWithOptions = profileSpace.delete(conditions, options).join();
List<?> crudDeleteOpts = client.eval("return crud_delete_opts").join();

assertEquals(true,
((HashMap<?, ?>) crudDeleteOpts.get(0)).get(ProxyOption.FETCH_LATEST_METADATA.toString()));
assertEquals(1, deleteResultWithOptions.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 All @@ -17,6 +18,7 @@
import io.tarantool.driver.core.ProxyTarantoolTupleClient;
import io.tarantool.driver.integration.SharedCartridgeContainer;
import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -30,6 +32,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Alexey Kuzin
Expand Down Expand Up @@ -188,4 +191,26 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(String.valueOf(i), tuple.getString(1));
}
}

@Test
public void withFetchLatestMetadata() {
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)
);
InsertManyOptions<ProxyInsertManyOptions> options = ProxyInsertManyOptions.create().fetchLatestMetadata();

assertTrue(options.getFetchLatestMetadata().isPresent());
assertTrue(options.getFetchLatestMetadata().get());

TarantoolResult<TarantoolTuple> insertManyResult = profileSpace.insertMany(tarantoolTuples, options).join();
List<?> crudInsertManyOpts = client.eval("return crud_insert_many_opts").join();

assertEquals(2, insertManyResult.size());
Assertions.assertEquals(true, ((HashMap<?, ?>) crudInsertManyOpts.get(0))
.get(ProxyOption.FETCH_LATEST_METADATA.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 All @@ -19,6 +20,7 @@
import io.tarantool.driver.integration.SharedCartridgeContainer;
import io.tarantool.driver.integration.Utils;
import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -267,4 +269,23 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(1, tuple.getInteger(0));
assertEquals("FIO", tuple.getString(1));
}

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

TarantoolTuple tarantoolTuple = tupleFactory.create(0, null, "0", 0, 0);
InsertOptions<ProxyInsertOptions> options = ProxyInsertOptions.create().fetchLatestMetadata();

assertTrue(options.getFetchLatestMetadata().isPresent());
assertTrue(options.getFetchLatestMetadata().get());

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

assertEquals(1, insertResult.size());
Assertions.assertEquals(true, ((HashMap<?, ?>) crudInsertOpts.get(0))
.get(ProxyOption.FETCH_LATEST_METADATA.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 All @@ -16,6 +17,7 @@
import io.tarantool.driver.core.ProxyTarantoolTupleClient;
import io.tarantool.driver.integration.SharedCartridgeContainer;
import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -29,6 +31,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Alexey Kuzin
Expand Down Expand Up @@ -171,4 +174,27 @@ public void withFieldsTest() throws ExecutionException, InterruptedException {
assertEquals(String.valueOf(i), tuple.getString(1));
}
}

@Test
public void withFetchLatestMetadata() {
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)
);

ReplaceManyOptions<ProxyReplaceManyOptions> options = ProxyReplaceManyOptions.create().fetchLatestMetadata();

assertTrue(options.getFetchLatestMetadata().isPresent());
assertTrue(options.getFetchLatestMetadata().get());

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

assertEquals(2, replaceManyResult.size());
Assertions.assertEquals(true, ((HashMap<?, ?>) crudReplaceManyOpts.get(0))
.get(ProxyOption.FETCH_LATEST_METADATA.toString()));
}
}
Loading

0 comments on commit 0687238

Please sign in to comment.