Skip to content

Commit

Permalink
Add support for "fetch_latest_metadata" option
Browse files Browse the repository at this point in the history
- Add option
- CHANGELOG.md

Closes #465
  • Loading branch information
nickkkccc committed Jan 29, 2024
1 parent 00dee2b commit cfa0ca1
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
- Bump testcontainers-java-tarantool version to 1.2.0 ([#442](https://github.com/tarantool/cartridge-java/issues/442))
- Bump netty version to 4.1.104.Final ([#446](https://github.com/tarantool/cartridge-java/issues/446))
- Bump msgpack-java version to 0.9.6
- Add support for crud `yield_every` option ([#458](https://github.com/tarantool/cartridge-java/pull/468))
- Add support for crud `force_map_call` option ([#459](https://github.com/tarantool/cartridge-java/pull/469))
- Add support for crud `fullscan` option ([#460](https://github.com/tarantool/cartridge-java/pull/470))
- Add support for crud `prefer_replica` option ([#461](https://github.com/tarantool/cartridge-java/pull/471))
- Add support for crud `balance` option ([#462](https://github.com/tarantool/cartridge-java/pull/472))
- Add support for crud `vshard_router` option ([#463](https://github.com/tarantool/cartridge-java/pull/473))
- Add support for crud `fetch_latest_metadata` option ([#465](https://github.com/tarantool/cartridge-java/pull/474))

### Features

Expand Down
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;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;
Expand All @@ -13,5 +14,5 @@
*/
public interface DeleteOptions<T extends DeleteOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
OperationWithVshardRouterOptions<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 @@ -13,5 +14,6 @@
*/
public interface InsertManyOptions<T extends InsertManyOptions<T>>
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>, OperationWithRollbackOnErrorOptions<T>,
OperationWithStopOnErrorOptions<T>, OperationWithVshardRouterOptions<T> {
OperationWithStopOnErrorOptions<T>, OperationWithVshardRouterOptions<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;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;
Expand All @@ -13,5 +14,5 @@
*/
public interface InsertOptions<T extends InsertOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
OperationWithVshardRouterOptions<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 @@ -13,5 +14,6 @@
*/
public interface ReplaceManyOptions<T extends ReplaceManyOptions<T>>
extends OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>, OperationWithRollbackOnErrorOptions<T>,
OperationWithStopOnErrorOptions<T>, OperationWithVshardRouterOptions<T> {
OperationWithStopOnErrorOptions<T>, OperationWithVshardRouterOptions<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;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;
Expand All @@ -13,5 +14,5 @@
*/
public interface ReplaceOptions<T extends ReplaceOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
OperationWithVshardRouterOptions<T>, OperationWithFetchLatestMetadataOptions<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.OperationWithBalanceOptions;
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.OperationWithFullScanOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithForceMapCallOptions;
Expand All @@ -24,5 +25,6 @@ public interface SelectOptions<T extends SelectOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithModeOptions<T>, OperationWithBatchSizeOptions<T>, OperationWithYieldEveryOptions<T>,
OperationWithForceMapCallOptions<T>, OperationWithFullScanOptions<T>, OperationWithPreferReplicaOptions<T>,
OperationWithBalanceOptions<T>, OperationWithVshardRouterOptions<T> {
OperationWithBalanceOptions<T>, OperationWithVshardRouterOptions<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;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;
Expand All @@ -13,5 +14,5 @@
*/
public interface UpdateOptions<T extends UpdateOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
OperationWithVshardRouterOptions<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;
import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions;
Expand All @@ -13,5 +14,5 @@
*/
public interface UpsertOptions<T extends UpsertOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithVshardRouterOptions<T> {
OperationWithVshardRouterOptions<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 @@ -35,7 +35,9 @@ public enum ProxyOption {

BALANCE("balance"),

VSHARD_ROUTER("vshard_router");
VSHARD_ROUTER("vshard_router"),

FETCH_LATEST_METADATA("fetch_latest_metadata");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,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 @@ -183,4 +184,26 @@ public void withVshardRouterTest() {
assertEquals(1, deleteResult.size());
assertEquals(0, selectResultAfterDelete.size());
}

@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 @@ -18,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 @@ -31,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 @@ -208,4 +210,26 @@ public void withVshardRouterTest() {
assertEquals(2, insertManyResult.size());
assertEquals(groupName, ((HashMap<?, ?>) crudInsertManyOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
}

@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 @@ -20,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 @@ -285,4 +286,23 @@ public void withVshardRouterTest() {
assertEquals(1, insertResult.size());
assertEquals(groupName, ((HashMap<?, ?>) crudInsertOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
}

@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 @@ -17,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 @@ -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 Alexey Kuzin
Expand Down Expand Up @@ -192,4 +194,27 @@ public void withVsharRouterTest() {
assertEquals(groupName, ((HashMap<?, ?>) crudReplaceManyOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
assertEquals(2, replaceResult.size());
}

@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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,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 @@ -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 @@ -185,4 +187,24 @@ public void withVsharRouterTest() {
assertEquals(1, replaceResult.size());
assertEquals(groupName, ((HashMap<?, ?>) crudReplaceOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString()));
}

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

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

ReplaceOptions<ProxyReplaceOptions> options = ProxyReplaceOptions.create().fetchLatestMetadata();

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

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

assertEquals(1, replaceResult.size());
Assertions.assertEquals(true, ((HashMap<?, ?>) crudReplaceOpts.get(0))
.get(ProxyOption.FETCH_LATEST_METADATA.toString()));
}
}
Loading

0 comments on commit cfa0ca1

Please sign in to comment.