Ejemplo n.º 1
0
  public Backend(Configuration storageConfig) {
    this.storageConfig = storageConfig;

    storeManager = getStorageManager(storageConfig);
    indexes = getIndexes(storageConfig);
    storeFeatures = storeManager.getFeatures();

    basicMetrics = storageConfig.getBoolean(BASIC_METRICS, BASIC_METRICS_DEFAULT);
    mergeBasicMetrics =
        storageConfig.getBoolean(MERGE_BASIC_METRICS_KEY, MERGE_BASIC_METRICS_DEFAULT);

    int bufferSizeTmp = storageConfig.getInt(BUFFER_SIZE_KEY, BUFFER_SIZE_DEFAULT);
    Preconditions.checkArgument(
        bufferSizeTmp >= 0, "Buffer size must be non-negative (use 0 to disable)");
    if (!storeFeatures.supportsBatchMutation()) {
      bufferSize = 0;
      log.debug("Buffering disabled because backend does not support batch mutations");
    } else bufferSize = bufferSizeTmp;

    writeAttempts = storageConfig.getInt(WRITE_ATTEMPTS_KEY, WRITE_ATTEMPTS_DEFAULT);
    Preconditions.checkArgument(writeAttempts > 0, "Write attempts must be positive");
    readAttempts = storageConfig.getInt(READ_ATTEMPTS_KEY, READ_ATTEMPTS_DEFAULT);
    Preconditions.checkArgument(readAttempts > 0, "Read attempts must be positive");
    persistAttemptWaittime =
        storageConfig.getInt(STORAGE_ATTEMPT_WAITTIME_KEY, STORAGE_ATTEMPT_WAITTIME_DEFAULT);
    Preconditions.checkArgument(
        persistAttemptWaittime > 0, "Persistence attempt retry wait time must be non-negative");

    // If lock prefix is unspecified, specify it now
    storageConfig.setProperty(
        ExpectedValueCheckingStore.LOCAL_LOCK_MEDIATOR_PREFIX_KEY,
        storageConfig.getString(
            ExpectedValueCheckingStore.LOCAL_LOCK_MEDIATOR_PREFIX_KEY, storeManager.getName()));

    final String lockBackendName =
        storageConfig.getString(
            GraphDatabaseConfiguration.LOCK_BACKEND,
            GraphDatabaseConfiguration.LOCK_BACKEND_DEFAULT);
    if (REGISTERED_LOCKERS.containsKey(lockBackendName)) {
      lockerCreator = REGISTERED_LOCKERS.get(lockBackendName);
    } else {
      throw new TitanConfigurationException(
          "Unknown lock backend \""
              + lockBackendName
              + "\".  Known lock backends: "
              + Joiner.on(", ").join(REGISTERED_LOCKERS.keySet())
              + ".");
    }
    // Never used for backends that have innate transaction support, but we
    // want to maintain the non-null invariant regardless; it will default
    // to connsistentkey impl if none is specified
    Preconditions.checkNotNull(lockerCreator);

    if (storeFeatures.isDistributed() && storeFeatures.isKeyOrdered()) {
      log.debug("Wrapping index store with HashPrefix");
      hashPrefixIndex = true;
    } else {
      hashPrefixIndex = false;
    }
  }
Ejemplo n.º 2
0
        @Override
        public Locker apply(String lockerName) {

          String expectedManagerName =
              "com.thinkaurelius.titan.diskstorage.cassandra.astyanax.AstyanaxStoreManager";
          String actualManagerName = storeManager.getClass().getCanonicalName();
          // Require AstyanaxStoreManager
          Preconditions.checkArgument(
              expectedManagerName.equals(actualManagerName),
              "Astyanax Recipe locker is only supported with the Astyanax storage backend (configured:"
                  + actualManagerName
                  + " != required:"
                  + expectedManagerName
                  + ")");

          try {
            Class<?> c = storeManager.getClass();
            Method method = c.getMethod("openLocker", String.class);
            Object o = method.invoke(storeManager, lockerName);
            return (Locker) o;
          } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException(
                "Could not find method when configuring locking with Astyanax Recipes");
          } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(
                "Could not access method when configuring locking with Astyanax Recipes", e);
          } catch (InvocationTargetException e) {
            throw new IllegalArgumentException(
                "Could not invoke method when configuring locking with Astyanax Recipes", e);
          }
        }
Ejemplo n.º 3
0
 private KeyColumnValueStore getBufferStore(String name) throws StorageException {
   Preconditions.checkArgument(
       bufferSize <= 1 || storeManager.getFeatures().supportsBatchMutation());
   KeyColumnValueStore store = null;
   store = storeManager.openDatabase(name);
   if (bufferSize > 1) {
     store = new BufferedKeyColumnValueStore(store, true);
   }
   // Enable cache
   store = new CachedKeyColumnValueStore(store);
   return store;
 }
 public TTLKVCSManager(KeyColumnValueStoreManager manager, int defaultTTL) {
   super(manager);
   Preconditions.checkArgument(
       supportsStoreTTL(manager),
       "Wrapped store must support cell or store level TTL: %s",
       manager);
   Preconditions.checkArgument(defaultTTL > 0, "Default TTL must b > 0: %s", defaultTTL);
   Preconditions.checkArgument(
       !manager.getFeatures().hasStoreTTL() || (manager instanceof CustomizeStoreKCVSManager));
   this.defaultTTL = defaultTTL;
   this.features = new StandardStoreFeatures.Builder(manager.getFeatures()).storeTTL(true).build();
   this.ttlEnabledStores = Maps.newHashMap();
 }
 private Log openLog(String logManagerName, String logName) {
   try {
     ModifiableConfiguration configuration =
         new ModifiableConfiguration(
             GraphDatabaseConfiguration.ROOT_NS,
             config.copy(),
             BasicConfiguration.Restriction.NONE);
     configuration.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "reader");
     configuration.set(
         GraphDatabaseConfiguration.LOG_READ_INTERVAL, Duration.ofMillis(500L), logManagerName);
     if (logStoreManager == null) {
       logStoreManager = Backend.getStorageManager(configuration);
     }
     StoreFeatures f = logStoreManager.getFeatures();
     boolean part = f.isDistributed() && f.isKeyOrdered();
     if (part) {
       for (String logname : new String[] {USER_LOG, TRANSACTION_LOG, MANAGEMENT_LOG})
         configuration.set(KCVSLogManager.LOG_MAX_PARTITIONS, 8, logname);
     }
     assert logStoreManager != null;
     if (!logManagers.containsKey(logManagerName)) {
       // Open log manager - only supports KCVSLog
       Configuration logConfig = configuration.restrictTo(logManagerName);
       Preconditions.checkArgument(
           logConfig.get(LOG_BACKEND).equals(LOG_BACKEND.getDefaultValue()));
       logManagers.put(logManagerName, new KCVSLogManager(logStoreManager, logConfig));
     }
     assert logManagers.containsKey(logManagerName);
     return logManagers.get(logManagerName).openLog(logName);
   } catch (BackendException e) {
     throw new TitanException("Could not open log: " + logName, e);
   }
 }
Ejemplo n.º 6
0
 /**
  * Clears the storage of all registered backend data providers. This includes backend storage
  * engines and index providers.
  *
  * <p>IMPORTANT: Clearing storage means that ALL data will be lost and cannot be recovered.
  *
  * @throws StorageException
  */
 public void clearStorage() throws StorageException {
   edgeStore.close();
   vertexIndexStore.close();
   edgeIndexStore.close();
   idAuthority.close();
   storeManager.clearStorage();
   // Indexes
   for (IndexProvider index : indexes.values()) index.clearStorage();
 }
 private void closeLogs() {
   try {
     for (LogManager lm : logManagers.values()) lm.close();
     logManagers.clear();
     if (logStoreManager != null) {
       logStoreManager.close();
       logStoreManager = null;
     }
   } catch (BackendException e) {
     throw new TitanException(e);
   }
 }
Ejemplo n.º 8
0
  /**
   * Opens a new transaction against all registered backend system wrapped in one {@link
   * BackendTransaction}.
   *
   * @return
   * @throws StorageException
   */
  public BackendTransaction beginTransaction(TransactionConfiguration configuration)
      throws StorageException {
    StoreTxConfig txConfig = new StoreTxConfig(configuration.getMetricsPrefix());
    if (configuration.hasTimestamp()) txConfig.setTimestamp(configuration.getTimestamp());
    StoreTransaction tx = storeManager.beginTransaction(txConfig);
    if (bufferSize > 1) {
      Preconditions.checkArgument(storeManager.getFeatures().supportsBatchMutation());
      tx =
          new BufferTransaction(
              tx, storeManager, bufferSize, writeAttempts, persistAttemptWaittime);
    }
    if (!storeFeatures.supportsLocking()) {
      if (storeFeatures.supportsTransactions()) {
        // No transaction wrapping needed
      } else if (storeFeatures.supportsConsistentKeyOperations()) {
        txConfig =
            new StoreTxConfig(ConsistencyLevel.KEY_CONSISTENT, configuration.getMetricsPrefix());
        if (configuration.hasTimestamp()) txConfig.setTimestamp(configuration.getTimestamp());
        tx =
            new ExpectedValueCheckingTransaction(
                tx, storeManager.beginTransaction(txConfig), readAttempts);
      }
    }

    // Index transactions
    Map<String, IndexTransaction> indexTx = new HashMap<String, IndexTransaction>(indexes.size());
    for (Map.Entry<String, IndexProvider> entry : indexes.entrySet()) {
      indexTx.put(entry.getKey(), new IndexTransaction(entry.getValue()));
    }

    return new BackendTransaction(
        tx,
        storeManager.getFeatures(),
        edgeStore,
        vertexIndexStore,
        edgeIndexStore,
        readAttempts,
        persistAttemptWaittime,
        indexTx);
  }
 public void close() throws StorageException {
   if (tx != null) tx.commit();
   store.close();
   manager.close();
 }
 public StoreTransaction startTx() throws StorageException {
   return manager.beginTransaction(new StoreTxConfig());
 }
 public void open() throws StorageException {
   manager = openStorageManager();
   store = manager.openDatabase(storeName);
   tx = startTx();
 }
Ejemplo n.º 12
0
 @Override
 public void shutdown() throws Exception {
   super.shutdown();
   storeManager.close();
 }
 public static boolean supportsStoreTTL(KeyColumnValueStoreManager manager) {
   return supportsStoreTTL(manager.getFeatures());
 }
Ejemplo n.º 14
0
 /**
  * Returns the {@link StoreFeatures} of the configured backend storage engine.
  *
  * @return
  */
 public StoreFeatures getStoreFeatures() {
   return storeManager.getFeatures();
 }
Ejemplo n.º 15
0
 private KeyColumnValueStore getStore(String name) throws StorageException {
   KeyColumnValueStore store = storeManager.openDatabase(name);
   return store;
 }