com.scalar.db.common.TableMetadataManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalardb Show documentation
Show all versions of scalardb Show documentation
A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases
package com.scalar.db.common;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.scalar.db.api.Admin;
import com.scalar.db.api.Operation;
import com.scalar.db.api.TableMetadata;
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.util.ThrowableFunction;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
/** A class that manages and caches table metadata */
@ThreadSafe
public class TableMetadataManager {
private final LoadingCache> tableMetadataCache;
public TableMetadataManager(Admin admin, long cacheExpirationTimeSecs) {
this(
key -> Optional.ofNullable(admin.getTableMetadata(key.namespace, key.table)),
cacheExpirationTimeSecs);
}
public TableMetadataManager(
ThrowableFunction, TableKey, Exception> getTableMetadataFunc,
long cacheExpirationTimeSecs) {
CacheBuilder