diff --git a/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/LogicalPersistentStore.java b/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/LogicalPersistentStore.java new file mode 100644 index 00000000000..186b874b979 --- /dev/null +++ b/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/LogicalPersistentStore.java @@ -0,0 +1,78 @@ +/* + * (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.atlasdb.persistent.api; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import javax.annotation.Nonnull; + +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore.StoreNamespace; + +public interface LogicalPersistentStore { + /** + * Retrieve the value associated with the given {@code key}. + * + * @param storeNamespace from which to retrieve the value + * @param key of the cache entry + * @return value associated or null if the entry is missing + */ + Optional get(StoreNamespace storeNamespace, @Nonnull K key); + + /** + * Retrieves values for all supplied {@code keys}. + * + * @param storeNamespace from which to retrieve the values + * @param keys for which entries we are interested in + * @return map of key, value pairs containing only entries which are stored + */ + Map get(StoreNamespace storeNamespace, List keys); + + /** + * Stores the given entry pair. + * + * @param storeNamespace where to store the entry + * @param key of the entry + * @param value of the entry + */ + void put(StoreNamespace storeNamespace, @Nonnull K key, @Nonnull V value); + + /** + * Stores all entry pairs specified in {@code toWrite}. + * + * @param storeNamespace where to store the entries + * @param toWrite entry pairs to store + */ + void put(StoreNamespace storeNamespace, Map toWrite); + + /** + * Creates a {@link StoreNamespace} with the given name. Multiple calls with the same {@code name} will return + * different namespaces. + * + * @param name of the namespace + * @return handle to the underlying namespace + */ + StoreNamespace createNamespace(@Nonnull String name); + + /** + * Given the namespace handle represented by {@code storeNamespace} drops the internal structures. + * + * @param storeNamespace which should be dropped + */ + void dropNamespace(StoreNamespace storeNamespace); +} diff --git a/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/PersistentTimestampStore.java b/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/PersistentTimestampStore.java deleted file mode 100644 index 8195efe9cc5..00000000000 --- a/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/PersistentTimestampStore.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.palantir.atlasdb.persistent.api; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.immutables.value.Value; - -import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; - -public interface PersistentTimestampStore extends AutoCloseable { - @Value.Immutable - interface StoreNamespace { - String humanReadableName(); - UUID uniqueName(); - } - - /** - * Gets the commit timestamp associated with the entry specified by {@code startTs}. - * - * @param storeNamespace handle to the namespace from which we want to retrieve the commit timestamp - * @param startTs entry key for which we want to retrieve commit timestamp - * @return the associated timestamp or null if the entry is missing - * @throws com.palantir.logsafe.exceptions.SafeIllegalArgumentException when {@code storeNamespace} is a - * handle to a non existing namespace - */ - @Nullable - Long get(StoreNamespace storeNamespace, @Nonnull Long startTs) throws SafeIllegalArgumentException; - - /** - * Gets the commit timestamps associated with the entries specified by {@code keys}. - * - * @param storeNamespace handle to the namespace from which we want to retrieve the commit timestamp - * @param keys representing start timestamps for which to retrieve commit timestamps - * @return a map for start to commit timestamp - */ - Map multiGet(StoreNamespace storeNamespace, List keys); - - /** - * Stores the {@code commitTs} for the associated {@code startTs} while overwriting the existing value in the - * specified {@code storeNamespace}. - * - * @param storeNamespace of the store to which we should store the entry - * @param startTs entry key - * @param commitTs entry value - * @throws com.palantir.logsafe.exceptions.SafeIllegalArgumentException when {@code storeNamespace} is a - * handle to a non existing namespace - */ - void put(StoreNamespace storeNamespace, @Nonnull Long startTs, @Nonnull Long commitTs) - throws SafeIllegalArgumentException; - - /** - * Stores the start to commit timestamp pairs given in {@code toWrite}, overwriting the existing values. - * - * @param storeNamespace of the store to which we should store the entry - * @param toWrite timestamp pairs to write - * @throws com.palantir.logsafe.exceptions.SafeIllegalArgumentException when {@code storeNamespace} is a - * handle to a non existing namespace - */ - void multiPut(StoreNamespace storeNamespace, Map toWrite); - - /** - * Creates a handle of type {@link StoreNamespace} with a {@link StoreNamespace#humanReadableName()} equals to - * {@code name}. Multiple calls with the same supplied {@code name} will generate multiple namespaces. Users of - * this API are required to keep uniqueness at the {@link StoreNamespace#humanReadableName()} level; otherwise, - * multiple {@link StoreNamespace} backed by internal data structures will be maintained for the same AtlasDB - * namespace, which is inefficient. - * - * @param name in human readable format of the namespace to be created - * @return {@link StoreNamespace} which represents a handle to the created namespace - */ - StoreNamespace createNamespace(@Nonnull String name); - - /** - * Drops the namespace specified by the supplied handle. Dropping of a namespace may fail if there are - * concurrent calls on the same namespace or if the namespace has already been dropped. - * - * @param storeNamespace handle - * @throws com.palantir.logsafe.exceptions.SafeIllegalArgumentException if the supplied {@code storeNamespace} is a - * handle to a non existing namespace - */ - void dropNamespace(StoreNamespace storeNamespace) throws SafeIllegalArgumentException; -} diff --git a/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/PhysicalPersistentStore.java b/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/PhysicalPersistentStore.java new file mode 100644 index 00000000000..fb0448dbcce --- /dev/null +++ b/atlasdb-api/src/main/java/com/palantir/atlasdb/persistent/api/PhysicalPersistentStore.java @@ -0,0 +1,98 @@ +/* + * (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.atlasdb.persistent.api; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +import javax.annotation.Nonnull; + +import org.immutables.value.Value; + +import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; + +import okio.ByteString; + +public interface PhysicalPersistentStore extends AutoCloseable { + @Value.Immutable + interface StoreNamespace { + String humanReadableName(); + UUID uniqueName(); + } + + /** + * Gets the value associated with the entry specified by {@code key}. + * + * @param storeNamespace handle to the namespace from which we want to retrieve the value + * @param key entry key for which we want to retrieve the value + * @return the {@link Optional} containing the value or empty if there is no associated value + * @throws SafeIllegalArgumentException when {@code storeNamespace} is a handle to a non existing namespace + */ + Optional get(StoreNamespace storeNamespace, @Nonnull ByteString key); + + /** + * Gets the values associated with the entries specified by {@code keys}. + * + * @param storeNamespace handle to the namespace from which we want to retrieve the values + * @param keys representing keys for which we want to retrieve the values + * @return a map from keys to values + */ + Map get(StoreNamespace storeNamespace, List keys); + + /** + * Stores the {@code value} for the associated {@code key} while overwriting the existing value in the specified + * {@code storeNamespace}. + * + * @param storeNamespace of the store to which we should store the entry + * @param key entry key + * @param value entry value + * @throws SafeIllegalArgumentException when {@code storeNamespace} is a handle to a non existing namespace + */ + void put(StoreNamespace storeNamespace, @Nonnull ByteString key, @Nonnull ByteString value); + + /** + * Stores the entry pairs given in {@code toWrite}, overwriting the existing values. + * + * @param storeNamespace of the store to which we should store the entry + * @param toWrite entry pairs to write + * @throws SafeIllegalArgumentException when {@code storeNamespace} is a handle to a non existing namespace + */ + void put(StoreNamespace storeNamespace, Map toWrite); + + /** + * Creates a handle of type {@link StoreNamespace} with a {@link StoreNamespace#humanReadableName()} equals to + * {@code name}. Multiple calls with the same supplied {@code name} will generate multiple namespaces. Users of this + * API are required to keep uniqueness at the {@link StoreNamespace#humanReadableName()} level; otherwise, multiple + * {@link StoreNamespace} backed by internal data structures will be maintained for the same AtlasDB namespace, + * which is inefficient. + * + * @param name in human readable format of the namespace to be created + * @return {@link StoreNamespace} which represents a handle to the created namespace + */ + StoreNamespace createNamespace(@Nonnull String name); + + /** + * Drops the namespace specified by the supplied handle. Dropping of a namespace may fail if there are concurrent + * calls on the same namespace or if the namespace has already been dropped. + * + * @param storeNamespace handle + * @throws SafeIllegalArgumentException if the {@code storeNamespace} does not exist + */ + void dropNamespace(StoreNamespace storeNamespace); +} diff --git a/atlasdb-client/src/main/java/com/palantir/atlasdb/cache/OffHeapTimestampCache.java b/atlasdb-client/src/main/java/com/palantir/atlasdb/cache/OffHeapTimestampCache.java index a925f22a063..d8c4f413079 100644 --- a/atlasdb-client/src/main/java/com/palantir/atlasdb/cache/OffHeapTimestampCache.java +++ b/atlasdb-client/src/main/java/com/palantir/atlasdb/cache/OffHeapTimestampCache.java @@ -41,8 +41,8 @@ import com.palantir.atlasdb.autobatch.Autobatchers; import com.palantir.atlasdb.autobatch.CoalescingRequestFunction; import com.palantir.atlasdb.autobatch.DisruptorAutobatcher; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore.StoreNamespace; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore.StoreNamespace; import com.palantir.common.streams.KeyedStream; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; import com.palantir.tritium.metrics.registry.MetricName; @@ -57,7 +57,7 @@ public final class OffHeapTimestampCache implements TimestampCache { private static final MetricName CACHE_NUKE = constructCacheMetricName("cacheNuke"); private static final MetricName CACHE_SIZE = constructCacheMetricName("cacheSize"); - private final PersistentTimestampStore persistentTimestampStore; + private final TimestampStore timestampStore; private final LongSupplier maxSize; private final AtomicReference cacheDescriptor = new AtomicReference<>(); private final TaggedMetricRegistry taggedMetricRegistry; @@ -65,10 +65,11 @@ public final class OffHeapTimestampCache implements TimestampCache { private final DisruptorAutobatcher, Map.Entry> timestampPutter; public static TimestampCache create( - PersistentTimestampStore persistentTimestampStore, + PhysicalPersistentStore physicalPersistentStore, TaggedMetricRegistry taggedMetricRegistry, LongSupplier maxSize) { - StoreNamespace storeNamespace = persistentTimestampStore.createNamespace(TIMESTAMP_CACHE_NAMESPACE); + TimestampStore timestampStore = new TimestampStore(physicalPersistentStore); + StoreNamespace storeNamespace = timestampStore.createNamespace(TIMESTAMP_CACHE_NAMESPACE); CacheDescriptor cacheDescriptor = ImmutableCacheDescriptor.builder() .currentSize(new AtomicInteger()) @@ -76,18 +77,18 @@ public static TimestampCache create( .build(); return new OffHeapTimestampCache( - persistentTimestampStore, + timestampStore, cacheDescriptor, maxSize, taggedMetricRegistry); } private OffHeapTimestampCache( - PersistentTimestampStore persistentTimestampStore, + TimestampStore timestampStore, CacheDescriptor cacheDescriptor, LongSupplier maxSize, TaggedMetricRegistry taggedMetricRegistry) { - this.persistentTimestampStore = persistentTimestampStore; + this.timestampStore = timestampStore; this.cacheDescriptor.set(cacheDescriptor); this.maxSize = maxSize; this.taggedMetricRegistry = taggedMetricRegistry; @@ -100,11 +101,11 @@ private OffHeapTimestampCache( @Override public void clear() { - CacheDescriptor proposedCacheDescriptor = createNamespaceAndConstructCacheProposal(persistentTimestampStore); + CacheDescriptor proposedCacheDescriptor = createNamespaceAndConstructCacheProposal(timestampStore); CacheDescriptor previous = cacheDescriptor.getAndUpdate(prev -> proposedCacheDescriptor); if (previous != null) { - persistentTimestampStore.dropNamespace(previous.storeNamespace()); + timestampStore.dropNamespace(previous.storeNamespace()); } } @@ -120,20 +121,27 @@ public void putAlreadyCommittedTransaction(Long startTimestamp, Long commitTimes @Nullable @Override public Long getCommitTimestampIfPresent(Long startTimestamp) { - Long value = Optional.ofNullable(inflightRequests.get(startTimestamp)) - .orElseGet(() -> persistentTimestampStore.get(cacheDescriptor.get().storeNamespace(), startTimestamp)); + Optional value = getCommitTimestamp(startTimestamp); - if (value == null) { - taggedMetricRegistry.meter(CACHE_MISS).mark(); - } else { + if (value.isPresent()) { taggedMetricRegistry.meter(CACHE_HIT).mark(); + } else { + taggedMetricRegistry.meter(CACHE_MISS).mark(); } - return value; + return value.orElse(null); + } + + private Optional getCommitTimestamp(Long startTimestamp) { + Long inFlight = inflightRequests.get(startTimestamp); + if (inFlight != null) { + return Optional.of(inFlight); + } + + return timestampStore.get(cacheDescriptor.get().storeNamespace(), startTimestamp); } - private static CacheDescriptor createNamespaceAndConstructCacheProposal( - PersistentTimestampStore persistentTimestampStore) { - StoreNamespace proposal = persistentTimestampStore.createNamespace(TIMESTAMP_CACHE_NAMESPACE); + private static CacheDescriptor createNamespaceAndConstructCacheProposal(TimestampStore timestampStore) { + StoreNamespace proposal = timestampStore.createNamespace(TIMESTAMP_CACHE_NAMESPACE); return ImmutableCacheDescriptor.builder() .currentSize(new AtomicInteger()) .storeNamespace(proposal) @@ -163,12 +171,12 @@ public Map, Map.Entry> apply(Set response = offHeapTimestampCache.persistentTimestampStore.multiGet( + Map response = offHeapTimestampCache.timestampStore.get( cacheDescriptor.storeNamespace(), request.stream().map(Map.Entry::getKey).collect(Collectors.toList())); Map toWrite = ImmutableMap.copyOf(Sets.difference(request, response.entrySet())); - offHeapTimestampCache.persistentTimestampStore.multiPut( + offHeapTimestampCache.timestampStore.put( cacheDescriptor.storeNamespace(), toWrite); @@ -185,7 +193,7 @@ public Map, Map.Entry> apply(Set { + private final PhysicalPersistentStore physicalPersistentStore; + + public TimestampStore(PhysicalPersistentStore physicalPersistentStore) { + this.physicalPersistentStore = physicalPersistentStore; + } + + @Nullable + @Override + public Optional get(StoreNamespace storeNamespace, @Nonnull Long startTs) { + ByteString byteKeyValue = toByteString(startTs); + return physicalPersistentStore.get(storeNamespace, byteKeyValue) + .map(value -> deserializeValue(startTs, value)); + } + + @Override + public Map get(StoreNamespace storeNamespace, List keys) { + + List byteKeys = keys.stream() + .map(ValueType.VAR_LONG::convertFromJava) + .map(ByteString::of) + .collect(Collectors.toList()); + + Map byteValues = physicalPersistentStore.get(storeNamespace, byteKeys); + + if (byteValues.isEmpty()) { + return ImmutableMap.of(); + } + + return KeyedStream.stream(byteValues) + .mapEntries(TimestampStore::deserializeEntry) + .collectToMap(); + } + + @Override + public void put(StoreNamespace storeNamespace, @Nonnull Long startTs, @Nonnull Long commitTs) { + ByteString key = toByteString(startTs); + ByteString value = toByteString(commitTs - startTs); + + physicalPersistentStore.put(storeNamespace, key, value); + } + + @Override + public void put(StoreNamespace storeNamespace, Map toWrite) { + KeyedStream.stream(toWrite).forEach((key, value) -> put(storeNamespace, key, value)); + } + + @Override + public StoreNamespace createNamespace(@Nonnull String name) { + return physicalPersistentStore.createNamespace(name); + } + + @Override + public void dropNamespace(StoreNamespace storeNamespace) { + physicalPersistentStore.dropNamespace(storeNamespace); + } + + private static Map.Entry deserializeEntry(ByteString key, ByteString value) { + Long deserializedKey = (Long) ValueType.VAR_LONG.convertToJava(key.toByteArray(), 0); + return Maps.immutableEntry(deserializedKey, deserializeValue(deserializedKey, value)); + } + + private static Long deserializeValue(Long key, ByteString value) { + if (value == null) { + return null; + } + return key + (Long) ValueType.VAR_LONG.convertToJava(value.toByteArray(), 0); + } + + private static ByteString toByteString(@Nonnull Long startTs) { + return ByteString.of(ValueType.VAR_LONG.convertFromJava(startTs)); + } +} diff --git a/atlasdb-client/src/main/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPersistentTimestampStore.java b/atlasdb-client/src/main/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPhysicalPersistentStore.java similarity index 72% rename from atlasdb-client/src/main/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPersistentTimestampStore.java rename to atlasdb-client/src/main/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPhysicalPersistentStore.java index 5c65f4486ad..71198628368 100644 --- a/atlasdb-client/src/main/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPersistentTimestampStore.java +++ b/atlasdb-client/src/main/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPhysicalPersistentStore.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -32,7 +33,6 @@ import java.util.stream.Stream; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import org.rocksdb.ColumnFamilyDescriptor; import org.rocksdb.ColumnFamilyHandle; @@ -46,52 +46,45 @@ import com.google.common.collect.Maps; import com.google.common.collect.Streams; import com.palantir.atlasdb.persistent.api.ImmutableStoreNamespace; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; -import com.palantir.atlasdb.table.description.ValueType; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; import com.palantir.common.streams.KeyedStream; import com.palantir.logsafe.Preconditions; import com.palantir.tracing.Tracers.ThrowingCallable; +import okio.ByteString; + /** - * Implementation of the {@link PersistentTimestampStore} using RocksDB as the underlying persistent storage. Commit - * timestamp associated with the start timestamp is encoded using delta encoding. Created {@link StoreNamespace}s are - * backed by RocksDB ColumnFamilies such that calling {@link RocksDbPersistentTimestampStore#createNamespace(String)} - * with the same name will construct a new {@link ColumnFamilyHandle} for each call. + * Implementation of the {@link PhysicalPersistentStore} using RocksDB as the underlying persistent storage. Created + * {@link StoreNamespace}s are backed by RocksDB ColumnFamilies such that calling + * {@link RocksDbPhysicalPersistentStore#createNamespace(String)} with the same name will construct a new + * {@link ColumnFamilyHandle} for each call. */ -public final class RocksDbPersistentTimestampStore implements PersistentTimestampStore { - private static final Logger log = LoggerFactory.getLogger(RocksDbPersistentTimestampStore.class); +public final class RocksDbPhysicalPersistentStore implements PhysicalPersistentStore { + private static final Logger log = LoggerFactory.getLogger(RocksDbPhysicalPersistentStore.class); private final ConcurrentMap availableColumnFamilies = new ConcurrentHashMap<>(); private final RocksDB rocksDB; private final File databaseFolder; - public RocksDbPersistentTimestampStore(RocksDB rocksDB, File databaseFolder) { + public RocksDbPhysicalPersistentStore(RocksDB rocksDB, File databaseFolder) { this.rocksDB = rocksDB; this.databaseFolder = databaseFolder; } @Override - @Nullable - public Long get(StoreNamespace storeNamespace, @Nonnull Long startTs) { + public Optional get(StoreNamespace storeNamespace, @Nonnull ByteString key) { checkNamespaceExists(storeNamespace); - byte[] byteKeyValue = ValueType.VAR_LONG.convertFromJava(startTs); - byte[] value = getValueBytes(availableColumnFamilies.get(storeNamespace.uniqueName()), byteKeyValue); - - return deserializeValue(startTs, value); + return getValueBytes(availableColumnFamilies.get(storeNamespace.uniqueName()), key); } @Override - public Map multiGet(StoreNamespace storeNamespace, List keys) { + public Map get(StoreNamespace storeNamespace, List keys) { checkNamespaceExists(storeNamespace); - List byteKeys = keys.stream() - .map(ValueType.VAR_LONG::convertFromJava) - .collect(Collectors.toList()); - - List byteValues = multiGetValueBytes( + List byteValues = multiGetValueByteStrings( availableColumnFamilies.get(storeNamespace.uniqueName()), - byteKeys); + keys); if (byteValues.isEmpty()) { return ImmutableMap.of(); @@ -101,23 +94,19 @@ public Map multiGet(StoreNamespace storeNamespace, List keys) Streams.zip( keys.stream(), byteValues.stream(), - (key, value) -> Maps.immutableEntry(key, deserializeValue(key, value)))) + Maps::immutableEntry)) .filter(Objects::nonNull) .collectToMap(); } @Override - public void put(StoreNamespace storeNamespace, @Nonnull Long startTs, @Nonnull Long commitTs) { + public void put(StoreNamespace storeNamespace, @Nonnull ByteString key, @Nonnull ByteString value) { checkNamespaceExists(storeNamespace); - - byte[] key = ValueType.VAR_LONG.convertFromJava(startTs); - byte[] value = ValueType.VAR_LONG.convertFromJava(commitTs - startTs); - putEntry(availableColumnFamilies.get(storeNamespace.uniqueName()), key, value); } @Override - public void multiPut(StoreNamespace storeNamespace, Map toWrite) { + public void put(StoreNamespace storeNamespace, Map toWrite) { KeyedStream.stream(toWrite).forEach((key, value) -> put(storeNamespace, key, value)); } @@ -158,13 +147,6 @@ public void close() throws IOException { } } - private Long deserializeValue(Long key, byte[] value) { - if (value == null) { - return null; - } - return key + (Long) ValueType.VAR_LONG.convertToJava(value, 0); - } - private UUID createColumnFamily() { UUID randomUuid = UUID.randomUUID(); ColumnFamilyHandle columnFamilyHandle = callWithExceptionHandling(() -> @@ -181,15 +163,22 @@ private void dropColumnFamily(StoreNamespace storeNamespace) { availableColumnFamilies.remove(storeNamespace.uniqueName()); } - private byte[] getValueBytes(ColumnFamilyHandle columnFamilyHandle, byte[] key) { + private Optional getValueBytes(ColumnFamilyHandle columnFamilyHandle, ByteString key) { try { - return rocksDB.get(columnFamilyHandle, key); + return Optional.ofNullable(rocksDB.get(columnFamilyHandle, key.toByteArray())).map(ByteString::of); } catch (RocksDBException exception) { log.warn("Rocks db raised an exception", exception); return null; } } + private List multiGetValueByteStrings(ColumnFamilyHandle columnFamilyHandle, List keys) { + List values = multiGetValueBytes( + columnFamilyHandle, + keys.stream().map(ByteString::toByteArray).collect(Collectors.toList())); + return values.stream().filter(Objects::nonNull).map(ByteString::of).collect(Collectors.toList()); + } + private List multiGetValueBytes(ColumnFamilyHandle columnFamilyHandle, List keys) { try { return rocksDB.multiGetAsList(Collections.nCopies(keys.size(), columnFamilyHandle), keys); @@ -199,9 +188,9 @@ private List multiGetValueBytes(ColumnFamilyHandle columnFamilyHandle, L } } - private void putEntry(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) { + private void putEntry(ColumnFamilyHandle columnFamilyHandle, ByteString key, ByteString value) { try { - rocksDB.put(columnFamilyHandle, key, value); + rocksDB.put(columnFamilyHandle, key.toByteArray(), value.toByteArray()); } catch (RocksDBException exception) { log.warn("Rocks db raised an exception", exception); } diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/cache/OffHeapTimestampCacheIntegrationTests.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/cache/RocksDbOffHeapTimestampCacheIntegrationTests.java similarity index 86% rename from atlasdb-client/src/test/java/com/palantir/atlasdb/cache/OffHeapTimestampCacheIntegrationTests.java rename to atlasdb-client/src/test/java/com/palantir/atlasdb/cache/RocksDbOffHeapTimestampCacheIntegrationTests.java index 305acdbd6d0..db688047c63 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/cache/OffHeapTimestampCacheIntegrationTests.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/cache/RocksDbOffHeapTimestampCacheIntegrationTests.java @@ -29,34 +29,34 @@ import org.rocksdb.RocksDB; import org.rocksdb.RocksDBException; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; -import com.palantir.atlasdb.persistent.rocksdb.RocksDbPersistentTimestampStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; +import com.palantir.atlasdb.persistent.rocksdb.RocksDbPhysicalPersistentStore; import com.palantir.atlasdb.util.MetricsManagers; -public final class OffHeapTimestampCacheIntegrationTests { +public final class RocksDbOffHeapTimestampCacheIntegrationTests { @ClassRule public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder(); private static final int CACHE_SIZE = 2; private TimestampCache offHeapTimestampCache; - private PersistentTimestampStore persistentTimestampStore; + private PhysicalPersistentStore physicalPersistentStore; @Before public void before() throws RocksDBException, IOException { File databaseFolder = TEMPORARY_FOLDER.newFolder(); RocksDB rocksDb = RocksDB.open(databaseFolder.getAbsolutePath()); - persistentTimestampStore = new RocksDbPersistentTimestampStore(rocksDb, databaseFolder); + physicalPersistentStore = new RocksDbPhysicalPersistentStore(rocksDb, databaseFolder); offHeapTimestampCache = OffHeapTimestampCache.create( - persistentTimestampStore, + physicalPersistentStore, MetricsManagers.createForTests().getTaggedRegistry(), () -> CACHE_SIZE); } @After public void after() throws Exception { - persistentTimestampStore.close(); + physicalPersistentStore.close(); } @Test diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/cache/RocksDbTimestampStoreTests.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/cache/RocksDbTimestampStoreTests.java new file mode 100644 index 00000000000..be8aebb3b5e --- /dev/null +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/cache/RocksDbTimestampStoreTests.java @@ -0,0 +1,94 @@ +/* + * (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.atlasdb.cache; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.rocksdb.RocksDB; +import org.rocksdb.RocksDBException; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore.StoreNamespace; +import com.palantir.atlasdb.persistent.rocksdb.RocksDbPhysicalPersistentStore; + +public final class RocksDbTimestampStoreTests { + @ClassRule + public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder(); + private static final String DEFAULT_NAMESPACE_NAME = "default"; + + private TimestampStore timestampStore; + private RocksDbPhysicalPersistentStore persistentStore; + private StoreNamespace defaultNamespace; + + @Before + public void before() throws RocksDBException, IOException { + File databaseFolder = TEMPORARY_FOLDER.newFolder(); + RocksDB rocksDb = RocksDB.open(databaseFolder.getAbsolutePath()); + + persistentStore = new RocksDbPhysicalPersistentStore(rocksDb, databaseFolder); + timestampStore = new TimestampStore(persistentStore); + + defaultNamespace = persistentStore.createNamespace(DEFAULT_NAMESPACE_NAME); + } + + @After + public void tearDown() throws IOException { + persistentStore.close(); + } + + @Test + public void emptyResult() { + assertThat(timestampStore.get(defaultNamespace, 1L)).isEmpty(); + } + + @Test + public void valueIsCorrectlyStored() { + timestampStore.put(defaultNamespace, 1L, 2L); + + assertThat(timestampStore.get(defaultNamespace, 1L)).hasValue(2L); + } + + @Test + public void multiGetFilters() { + timestampStore.put(defaultNamespace, 1L, 2L); + timestampStore.put(defaultNamespace, 2L, 3L); + + assertThat(timestampStore.get(defaultNamespace, ImmutableList.of(1L, 2L, 3L))) + .containsExactlyInAnyOrderEntriesOf( + ImmutableMap.of( + 1L, 2L, + 2L, 3L)); + } + + @Test + public void multiPutCorrectlyStores() { + timestampStore.put(defaultNamespace, ImmutableMap.of(1L, 2L, 3L, 4L)); + + assertThat(timestampStore.get(defaultNamespace, 1L)).hasValue(2L); + assertThat(timestampStore.get(defaultNamespace, 3L)).hasValue(4L); + assertThat(timestampStore.get(defaultNamespace, 5L)).isEmpty(); + } +} diff --git a/atlasdb-client/src/test/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPersistentTimestampStoreTests.java b/atlasdb-client/src/test/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPhysicalPersistentStoreTests.java similarity index 67% rename from atlasdb-client/src/test/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPersistentTimestampStoreTests.java rename to atlasdb-client/src/test/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPhysicalPersistentStoreTests.java index 3505014ab41..ff7becde37d 100644 --- a/atlasdb-client/src/test/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPersistentTimestampStoreTests.java +++ b/atlasdb-client/src/test/java/com/palantir/atlasdb/persistent/rocksdb/RocksDbPhysicalPersistentStoreTests.java @@ -32,11 +32,13 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.palantir.atlasdb.persistent.api.ImmutableStoreNamespace; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore.StoreNamespace; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore.StoreNamespace; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; -public final class RocksDbPersistentTimestampStoreTests { +import okio.ByteString; + +public final class RocksDbPhysicalPersistentStoreTests { @ClassRule public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -45,8 +47,12 @@ public final class RocksDbPersistentTimestampStoreTests { .humanReadableName("bla") .uniqueName(UUID.randomUUID()) .build(); + private static final ByteString KEY = ByteString.encodeUtf8("key"); + private static final ByteString VALUE = ByteString.encodeUtf8("value"); + private static final ByteString KEY2 = ByteString.encodeUtf8("key2"); + private static final ByteString VALUE2 = ByteString.encodeUtf8("value2"); - private PersistentTimestampStore timestampMappingStore; + private PhysicalPersistentStore timestampMappingStore; private StoreNamespace defaultNamespace; @Before @@ -54,7 +60,7 @@ public void before() throws Exception { File databaseFolder = temporaryFolder.newFolder(); RocksDB rocksDb = RocksDB.open(databaseFolder.getAbsolutePath()); - timestampMappingStore = new RocksDbPersistentTimestampStore(rocksDb, databaseFolder); + timestampMappingStore = new RocksDbPhysicalPersistentStore(rocksDb, databaseFolder); defaultNamespace = timestampMappingStore.createNamespace(DEFAULT); } @@ -65,13 +71,13 @@ public void after() throws Exception { @Test public void entryMissing() { - assertThat(timestampMappingStore.get(defaultNamespace, 1L)).isNull(); + assertThat(timestampMappingStore.get(defaultNamespace, KEY)).isEmpty(); } @Test public void correctlyStored() { - timestampMappingStore.put(defaultNamespace, 1L, 3L); - assertThat(timestampMappingStore.get(defaultNamespace, 1L)).isEqualTo(3L); + timestampMappingStore.put(defaultNamespace, KEY, VALUE); + assertThat(timestampMappingStore.get(defaultNamespace, KEY)).hasValue(VALUE); } @Test @@ -79,8 +85,8 @@ public void storeNamespaceUniqueness() { StoreNamespace differentDefault = timestampMappingStore.createNamespace(DEFAULT); assertThat(differentDefault).isNotEqualTo(defaultNamespace); - timestampMappingStore.put(defaultNamespace, 1L, 3L); - assertThat(timestampMappingStore.get(differentDefault, 1L)).isNull(); + timestampMappingStore.put(defaultNamespace, KEY, VALUE); + assertThat(timestampMappingStore.get(differentDefault, KEY)).isEmpty(); timestampMappingStore.dropNamespace(differentDefault); } @@ -92,13 +98,13 @@ public void droppingNonExistingFails() { @Test public void getOnNonExistingFails() { - assertThatThrownBy(() -> timestampMappingStore.get(NON_EXISTING_NAMESPACE, 1L)) + assertThatThrownBy(() -> timestampMappingStore.get(NON_EXISTING_NAMESPACE, KEY)) .isInstanceOf(SafeIllegalArgumentException.class); } @Test public void putOnNonExistingFails() { - assertThatThrownBy(() -> timestampMappingStore.put(NON_EXISTING_NAMESPACE, 1L, 2L)) + assertThatThrownBy(() -> timestampMappingStore.put(NON_EXISTING_NAMESPACE, KEY, VALUE)) .isInstanceOf(SafeIllegalArgumentException.class); } @@ -113,23 +119,24 @@ public void droppingTwoTimesFailsOnSecond() { @Test public void testMultiPut() { - timestampMappingStore.multiPut( + timestampMappingStore.put( defaultNamespace, - ImmutableMap.of(1L, 2L, 3L, 4L)); + ImmutableMap.of(KEY, VALUE, KEY2, VALUE2)); - assertThat(timestampMappingStore.get(defaultNamespace, 1L)).isEqualTo(2L); - assertThat(timestampMappingStore.get(defaultNamespace, 3L)).isEqualTo(4L); + assertThat(timestampMappingStore.get(defaultNamespace, KEY)).hasValue(VALUE); + assertThat(timestampMappingStore.get(defaultNamespace, KEY2)).hasValue(VALUE2); } @Test public void testMultiGet() { - timestampMappingStore.put(defaultNamespace, 1L, 2L); - timestampMappingStore.put(defaultNamespace, 3L, 4L); + timestampMappingStore.put(defaultNamespace, KEY, VALUE); + timestampMappingStore.put(defaultNamespace, KEY2, VALUE2); - assertThat(timestampMappingStore.multiGet(defaultNamespace, ImmutableList.of(1L, 2L, 3L))) + assertThat( + timestampMappingStore.get(defaultNamespace, ImmutableList.of(KEY, KEY2, ByteString.encodeUtf8("bla")))) .containsExactlyInAnyOrderEntriesOf(ImmutableMap.of( - 1L, 2L, - 3L, 4L) + KEY, VALUE, + KEY2, VALUE2) ); } } diff --git a/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/DefaultPersistentStorageFactory.java b/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/DefaultPhysicalPersistentStorageFactory.java similarity index 65% rename from atlasdb-config/src/main/java/com/palantir/atlasdb/factory/DefaultPersistentStorageFactory.java rename to atlasdb-config/src/main/java/com/palantir/atlasdb/factory/DefaultPhysicalPersistentStorageFactory.java index 521874c01a9..179b374c862 100644 --- a/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/DefaultPersistentStorageFactory.java +++ b/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/DefaultPhysicalPersistentStorageFactory.java @@ -25,27 +25,27 @@ import org.slf4j.LoggerFactory; import com.palantir.atlasdb.config.RocksDbPersistentStorageConfig; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; -import com.palantir.atlasdb.persistent.rocksdb.RocksDbPersistentTimestampStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; +import com.palantir.atlasdb.persistent.rocksdb.RocksDbPhysicalPersistentStore; /** - * Constructs a new {@link PersistentTimestampStore} with new persistent storage connection on each call of - * {@link DefaultPersistentStorageFactory#constructPersistentTimestampStore(RocksDbPersistentStorageConfig)}. + * Constructs a new {@link PhysicalPersistentStore} with new persistent storage connection on each call of + * {@link DefaultPhysicalPersistentStorageFactory#constructPersistentStore(RocksDbPersistentStorageConfig)}. */ -public final class DefaultPersistentStorageFactory implements PersistentStorageFactory { - private static final Logger log = LoggerFactory.getLogger(DefaultPersistentStorageFactory.class); +public final class DefaultPhysicalPersistentStorageFactory implements PhysicalPersistentStorageFactory { + private static final Logger log = LoggerFactory.getLogger(DefaultPhysicalPersistentStorageFactory.class); /** - * Constructs a {@link PersistentTimestampStore} from a {@link RocksDbPersistentStorageConfig}. + * Constructs a {@link PhysicalPersistentStore} from a {@link RocksDbPersistentStorageConfig}. * * @param config of the requested RocksDB persistent storage - * @return RockDB implementation of {@link PersistentTimestampStore} + * @return RockDB implementation of {@link PhysicalPersistentStore} */ - public PersistentTimestampStore constructPersistentTimestampStore(RocksDbPersistentStorageConfig config) { + public PhysicalPersistentStore constructPersistentStore(RocksDbPersistentStorageConfig config) { PersistentStorageFactories.sanitizeStoragePath(config.storagePath()); File databaseFolder = new File(config.storagePath(), UUID.randomUUID().toString()); RocksDB rocksDb = openRocksConnection(databaseFolder); - return new RocksDbPersistentTimestampStore(rocksDb, databaseFolder); + return new RocksDbPhysicalPersistentStore(rocksDb, databaseFolder); } private static RocksDB openRocksConnection(File databaseFolder) { diff --git a/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/PersistentStorageFactory.java b/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/PhysicalPersistentStorageFactory.java similarity index 68% rename from atlasdb-config/src/main/java/com/palantir/atlasdb/factory/PersistentStorageFactory.java rename to atlasdb-config/src/main/java/com/palantir/atlasdb/factory/PhysicalPersistentStorageFactory.java index eeaa477c2bd..3b96739a469 100644 --- a/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/PersistentStorageFactory.java +++ b/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/PhysicalPersistentStorageFactory.java @@ -17,14 +17,15 @@ package com.palantir.atlasdb.factory; import com.palantir.atlasdb.config.RocksDbPersistentStorageConfig; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; +import com.palantir.atlasdb.persistent.rocksdb.RocksDbPhysicalPersistentStore; -public interface PersistentStorageFactory { +public interface PhysicalPersistentStorageFactory { /** - * Constructs a {@link com.palantir.atlasdb.persistent.rocksdb.RocksDbPersistentTimestampStore} using the - * supplied configuration. + * Constructs a {@link RocksDbPhysicalPersistentStore} using the supplied configuration. + * * @param config to use to configure the store * @return store to be used */ - PersistentTimestampStore constructPersistentTimestampStore(RocksDbPersistentStorageConfig config); + PhysicalPersistentStore constructPersistentStore(RocksDbPersistentStorageConfig config); } diff --git a/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/TransactionManagers.java b/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/TransactionManagers.java index f25e5c8ab69..604a156bf82 100644 --- a/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/TransactionManagers.java +++ b/atlasdb-config/src/main/java/com/palantir/atlasdb/factory/TransactionManagers.java @@ -98,7 +98,7 @@ import com.palantir.atlasdb.keyvalue.impl.ValidatingQueryRewritingKeyValueService; import com.palantir.atlasdb.logging.KvsProfilingLogger; import com.palantir.atlasdb.memory.InMemoryAtlasDbConfig; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; import com.palantir.atlasdb.persistentlock.CheckAndSetExceptionMapper; import com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService; import com.palantir.atlasdb.persistentlock.NoOpPersistentLockService; @@ -236,8 +236,8 @@ boolean allSafeForLogging() { abstract TaggedMetricRegistry globalTaggedMetricRegistry(); @Value.Default - PersistentStorageFactory persistentStorageFactory() { - return new DefaultPersistentStorageFactory(); + PhysicalPersistentStorageFactory persistentStorageFactory() { + return new DefaultPhysicalPersistentStorageFactory(); } /** @@ -431,14 +431,14 @@ private TransactionManager serializableInternal(@Output List clos this::withConsolidatedGrabImmutableTsLockFlag, () -> runtimeConfigSupplier.get().transaction()); - Optional persistentTimestampStore = - constructPersistentTimestampStoreIfConfigured(config(), persistentStorageFactory(), closeables); + Optional persistentStore = + constructPersistentStoreIfConfigured(config(), persistentStorageFactory(), closeables); TimestampCache timestampCache = instrumentedTimestampCache( config(), metricsManager, runtimeConfigSupplier, - persistentTimestampStore); + persistentStore); ConflictTracer conflictTracer = lockDiagnosticInfoCollector() .map(Function.identity()) @@ -510,9 +510,9 @@ metricsManager, persistentLockService, config().getSweepPersistentLockWaitMillis } @VisibleForTesting - static Optional constructPersistentTimestampStoreIfConfigured( + static Optional constructPersistentStoreIfConfigured( AtlasDbConfig config, - PersistentStorageFactory persistentStorageFactory, + PhysicalPersistentStorageFactory physicalPersistentStorageFactory, @Output List closeables) { return initializeCloseable( config.persistentStorage().map(storageConfig -> { @@ -520,8 +520,8 @@ static Optional constructPersistentTimestampStoreIfCon storageConfig instanceof RocksDbPersistentStorageConfig, "Storage config is not RocksDbPersistentStorageConfig.", SafeArg.of("configClass", storageConfig.getClass())); - return persistentStorageFactory - .constructPersistentTimestampStore((RocksDbPersistentStorageConfig) storageConfig); + return physicalPersistentStorageFactory + .constructPersistentStore((RocksDbPersistentStorageConfig) storageConfig); }), closeables); } @@ -531,7 +531,7 @@ static TimestampCache timestampCache( AtlasDbConfig config, MetricsManager metricsManager, Supplier runtimeConfig, - Optional timestampStore) { + Optional timestampStore) { LongSupplier cacheSize = () -> runtimeConfig.get().getTimestampCacheSize(); Supplier timestampCacheSupplier = () -> timestampStore.map(store -> @@ -545,7 +545,7 @@ private static TimestampCache instrumentedTimestampCache( AtlasDbConfig config, MetricsManager metricsManager, Supplier runtimeConfig, - Optional timestampStore) { + Optional timestampStore) { TimestampCache timestampCache = timestampCache(config, metricsManager, runtimeConfig, timestampStore); return AtlasDbMetrics.instrumentTimed( diff --git a/atlasdb-config/src/test/java/com/palantir/atlasdb/factory/DefaultPersistentStorageFactoryTests.java b/atlasdb-config/src/test/java/com/palantir/atlasdb/factory/DefaultPhysicalPersistentStorageFactoryTests.java similarity index 80% rename from atlasdb-config/src/test/java/com/palantir/atlasdb/factory/DefaultPersistentStorageFactoryTests.java rename to atlasdb-config/src/test/java/com/palantir/atlasdb/factory/DefaultPhysicalPersistentStorageFactoryTests.java index b083ae7b153..71fadf54bfd 100644 --- a/atlasdb-config/src/test/java/com/palantir/atlasdb/factory/DefaultPersistentStorageFactoryTests.java +++ b/atlasdb-config/src/test/java/com/palantir/atlasdb/factory/DefaultPhysicalPersistentStorageFactoryTests.java @@ -31,9 +31,9 @@ import com.google.common.collect.ImmutableList; import com.palantir.atlasdb.config.ImmutableRocksDbPersistentStorageConfig; import com.palantir.atlasdb.config.RocksDbPersistentStorageConfig; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; -public final class DefaultPersistentStorageFactoryTests { +public final class DefaultPhysicalPersistentStorageFactoryTests { @Rule public TemporaryFolder testFolder = new TemporaryFolder(Files.currentFolder()); @@ -52,12 +52,12 @@ public void createsPersistentStorage() throws Exception { RocksDbPersistentStorageConfig config = ImmutableRocksDbPersistentStorageConfig.builder() .storagePath(storagePath) .build(); - PersistentTimestampStore persistentTimestampStore = new DefaultPersistentStorageFactory() - .constructPersistentTimestampStore(config); + PhysicalPersistentStore physicalPersistentStore = new DefaultPhysicalPersistentStorageFactory() + .constructPersistentStore(config); assertThat(testFolderContent()).hasSize(1); - persistentTimestampStore.close(); + physicalPersistentStore.close(); assertThat(testFolderContent()).isEmpty(); } @@ -67,10 +67,10 @@ public void createsMultiplePersistentStores() throws Exception { RocksDbPersistentStorageConfig config = ImmutableRocksDbPersistentStorageConfig.builder() .storagePath(storagePath) .build(); - PersistentStorageFactory factory = new DefaultPersistentStorageFactory(); + PhysicalPersistentStorageFactory factory = new DefaultPhysicalPersistentStorageFactory(); - PersistentTimestampStore firstStore = factory.constructPersistentTimestampStore(config); - PersistentTimestampStore secondStore = factory.constructPersistentTimestampStore(config); + PhysicalPersistentStore firstStore = factory.constructPersistentStore(config); + PhysicalPersistentStore secondStore = factory.constructPersistentStore(config); assertThat(firstStore).isNotEqualTo(secondStore); diff --git a/atlasdb-config/src/test/java/com/palantir/atlasdb/factory/TransactionManagersTest.java b/atlasdb-config/src/test/java/com/palantir/atlasdb/factory/TransactionManagersTest.java index 48335c493d4..66e027b4894 100644 --- a/atlasdb-config/src/test/java/com/palantir/atlasdb/factory/TransactionManagersTest.java +++ b/atlasdb-config/src/test/java/com/palantir/atlasdb/factory/TransactionManagersTest.java @@ -100,7 +100,7 @@ import com.palantir.atlasdb.keyvalue.impl.SweepStatsKeyValueService; import com.palantir.atlasdb.memory.InMemoryAsyncAtlasDbConfig; import com.palantir.atlasdb.memory.InMemoryAtlasDbConfig; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; import com.palantir.atlasdb.sweep.queue.config.ImmutableTargetedSweepInstallConfig; import com.palantir.atlasdb.sweep.queue.config.ImmutableTargetedSweepRuntimeConfig; import com.palantir.atlasdb.table.description.GenericTestSchema; @@ -766,42 +766,42 @@ public void usingPersistentStorage() throws IOException { .build()) .build(); - Optional persistentTimestampStore = - TransactionManagers.constructPersistentTimestampStoreIfConfigured( + Optional persistentStore = + TransactionManagers.constructPersistentStoreIfConfigured( installConfig, - new DefaultPersistentStorageFactory(), + new DefaultPhysicalPersistentStorageFactory(), new LinkedList<>()); - TimestampCache timestampCache = constructTimestampCache(installConfig, persistentTimestampStore); + TimestampCache timestampCache = constructTimestampCache(installConfig, persistentStore); assertThat(timestampCache).isInstanceOf(OffHeapTimestampCache.class); } @Test - public void persistentTimestampStoreNotConstructed() { + public void persistentStoreNotConstructed() { AtlasDbConfig installConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAtlasDbConfig()) .targetedSweep(ImmutableTargetedSweepInstallConfig.builder().build()) .build(); - Optional persistentTimestampStore = - TransactionManagers.constructPersistentTimestampStoreIfConfigured( + Optional persistentStore = + TransactionManagers.constructPersistentStoreIfConfigured( installConfig, - new DefaultPersistentStorageFactory(), + new DefaultPhysicalPersistentStorageFactory(), new LinkedList<>()); - assertThat(persistentTimestampStore) + assertThat(persistentStore) .isEmpty(); } private TimestampCache constructTimestampCache( AtlasDbConfig installConfig, - Optional persistentTimestampStore) { + Optional persistentStore) { return TransactionManagers.timestampCache( installConfig, metricsManager, () -> ImmutableAtlasDbRuntimeConfig.builder().build(), - persistentTimestampStore); + persistentStore); } private KeyValueService initializeKeyValueServiceWithSweepSettings( diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/ComparingTimestampCache.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/ComparingTimestampCache.java index f226d500e9f..1cc602d8a0e 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/ComparingTimestampCache.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/ComparingTimestampCache.java @@ -24,7 +24,7 @@ import com.palantir.atlasdb.cache.DefaultTimestampCache; import com.palantir.atlasdb.cache.OffHeapTimestampCache; import com.palantir.atlasdb.cache.TimestampCache; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; import com.palantir.atlasdb.util.MetricsManager; import com.palantir.logsafe.Preconditions; import com.palantir.logsafe.SafeArg; @@ -35,13 +35,13 @@ public final class ComparingTimestampCache implements TimestampCache { public static TimestampCache comparingOffHeapForTests( MetricsManager metricRegistry, - PersistentTimestampStore persistentTimestampStore) { + PhysicalPersistentStore physicalPersistentStore) { TimestampCache first = new DefaultTimestampCache( metricRegistry.getRegistry(), () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE); TimestampCache second = OffHeapTimestampCache.create( - persistentTimestampStore, + physicalPersistentStore, metricRegistry.getTaggedRegistry(), () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE); diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/TransactionTestSetup.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/TransactionTestSetup.java index a3124fcef8e..73c64058976 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/TransactionTestSetup.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/TransactionTestSetup.java @@ -42,8 +42,8 @@ import com.palantir.atlasdb.keyvalue.impl.Cells; import com.palantir.atlasdb.keyvalue.impl.KvsManager; import com.palantir.atlasdb.keyvalue.impl.TransactionManagerManager; -import com.palantir.atlasdb.persistent.api.PersistentTimestampStore; -import com.palantir.atlasdb.persistent.rocksdb.RocksDbPersistentTimestampStore; +import com.palantir.atlasdb.persistent.api.PhysicalPersistentStore; +import com.palantir.atlasdb.persistent.rocksdb.RocksDbPhysicalPersistentStore; import com.palantir.atlasdb.protos.generated.TableMetadataPersistence.SweepStrategy; import com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter; import com.palantir.atlasdb.table.description.TableMetadata; @@ -66,18 +66,18 @@ public abstract class TransactionTestSetup { @ClassRule public static final TemporaryFolder PERSISTENT_STORAGE_FOLDER = new TemporaryFolder(); - private static PersistentTimestampStore persistentTimestampStore; + private static PhysicalPersistentStore physicalPersistentStore; @BeforeClass public static void storageSetUp() throws IOException, RocksDBException { File storageDirectory = PERSISTENT_STORAGE_FOLDER.newFolder(); RocksDB rocksDb = RocksDB.open(storageDirectory.getAbsolutePath()); - persistentTimestampStore = new RocksDbPersistentTimestampStore(rocksDb, storageDirectory); + physicalPersistentStore = new RocksDbPhysicalPersistentStore(rocksDb, storageDirectory); } @AfterClass public static void storageTearDown() throws Exception { - persistentTimestampStore.close(); + physicalPersistentStore.close(); } protected static final TableReference TEST_TABLE = TableReference.createFromFullyQualifiedName( @@ -110,7 +110,7 @@ protected TransactionTestSetup(KvsManager kvsManager, TransactionManagerManager @Before public void setUp() { - timestampCache = ComparingTimestampCache.comparingOffHeapForTests(metricsManager, persistentTimestampStore); + timestampCache = ComparingTimestampCache.comparingOffHeapForTests(metricsManager, physicalPersistentStore); lockService = LockServiceImpl.create(LockServerOptions.builder().isStandaloneServer(false).build()); lockClient = LockClient.of("test_client");