예제 #1
0
  @Override
  public ISchematicCursor getCursor(
      ExecutionContext executionContext, IndexMeta indexMeta, String actualTableName)
      throws TddlException {
    Database db = getDatabase(actualTableName);
    if (db == null) {
      throw new TddlException("table don't contains indexName:" + actualTableName);
    }
    ITransaction txn = executionContext.getTransaction();
    CursorConfig cc = CursorConfig.DEFAULT;
    LockMode lm = LockMode.DEFAULT;
    if (txn != null) {
      com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config;
      if (_config.getReadUncommitted()) {
        cc = CursorConfig.READ_UNCOMMITTED;
        lm = LockMode.READ_UNCOMMITTED;
      } else if (_config.getReadCommitted()) {
        cc = CursorConfig.READ_COMMITTED;
        // lm = LockMode.READ_COMMITTED;
      }
    } else {

      cc = CursorConfig.READ_COMMITTED;
    }
    JE_Cursor je_cursor =
        new JE_Cursor(
            indexMeta, db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm);
    if (txn != null) {
      ((JE_Transaction) txn).addCursor(je_cursor);
    }
    return new SchematicCursor(
        je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta));
  }
  /** Write data into the database. */
  private void generateData(
      Environment master, int numTxns, Durability durability, boolean doCommit) {

    /* Write some data. */
    DatabaseEntry key = new DatabaseEntry();
    byte[] dataPadding = new byte[1000];
    DatabaseEntry data = new DatabaseEntry(dataPadding);

    TransactionConfig txnConfig = new TransactionConfig();
    txnConfig.setDurability(durability);

    for (int i = 0; i < numTxns; i++) {
      final Transaction txn = master.beginTransaction(null, txnConfig);
      //            long keyPrefix = i << 10;
      //            LongBinding.longToEntry(keyPrefix + i, key);
      LongBinding.longToEntry(i, key);
      db.put(txn, key, data);

      if (doCommit) {
        txn.commit();
      } else {
        txn.abort();
      }
    }
  }
예제 #3
0
  private void openEnvironment(File file) throws DatabaseInitException {
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setCachePercent(30);
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    envConfig.setTxnTimeout(10, TimeUnit.SECONDS);
    envConfig.setLockTimeout(2000, TimeUnit.MILLISECONDS);
    try {
      environment = new Environment(file, envConfig);
      transactionConfig = new TransactionConfig();
      transactionConfig.setReadCommitted(true);

      cursorConfig = new CursorConfig();
      cursorConfig.setReadCommitted(true);
    } catch (EnvironmentLockedException e) {
      String message =
          "Environment locked exception. Another process is using the same database, or the current user has no write access (database location: \""
              + file.getAbsolutePath()
              + "\")";
      throw new DatabaseInitException(message);
    } catch (DatabaseException e) {
      String message = "A database initialisation error has occured (" + e.getMessage() + ")";
      throw new DatabaseInitException(message);
    }
  }
 protected BerkeleyDBTransaction(
     BerkeleyDBPersistenceManager persistenceManager, TransactionConfig config, long timeOut) {
   super(persistenceManager);
   try {
     this.dbTransaction = persistenceManager.getEnvironment().beginTransaction(null, config);
     persistenceManager.registerTransaction(this);
     this.dbTransaction.setLockTimeout(timeOut, TimeUnit.MILLISECONDS);
     this.defaultCursorConfig = new CursorConfig();
     this.defaultCursorConfig.setReadCommitted(config.getReadCommitted());
     this.defaultCursorConfig.setReadUncommitted(config.getReadUncommitted());
     this.timeOut = timeOut;
     this.openedCursors =
         Collections.synchronizedMap(new HashMap<EntityCursor<?>, List<StackTraceElement>>());
   } catch (DatabaseException e) {
     throw getPersistenceManager().convertDatabaseException(e);
   }
 }
  /** Used when creating ReplayTxns at recovery. No ActiveTxns map is available. */
  public ReplayTxn(EnvironmentImpl envImpl, TransactionConfig config, long txnId, Logger logger)
      throws DatabaseException {

    super(
        envImpl, config, null, // ReplicationContext set later
        txnId); // mandatedId
    /* Preempt reader transactions when a lock conflict occurs. */
    setImportunate(true);
    this.logger = logger;
    assert !config.getLocalWrite();
  }
예제 #6
0
 public ISchematicCursor getCursor(
     ITransaction txn, IndexMeta indexMeta, String isolation, String actualTableName)
     throws TddlException {
   Database db = getDatabase(actualTableName);
   if (db == null) {
     throw new TddlException("table don't contains indexName:" + actualTableName);
   }
   CursorConfig cc = CursorConfig.DEFAULT;
   LockMode lm = LockMode.DEFAULT;
   if (txn != null) {
     com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config;
     if (_config.getReadUncommitted()) {
       cc = CursorConfig.READ_UNCOMMITTED;
       lm = LockMode.READ_UNCOMMITTED;
     } else if (_config.getReadCommitted()) {
       cc = CursorConfig.READ_COMMITTED;
       // lm = LockMode.READ_COMMITTED;
     }
   } else {
     if (Isolation.READ_COMMITTED.equals(isolation)) {
       cc = CursorConfig.READ_COMMITTED;
       // lm = LockMode.READ_COMMITTED;//not support
     } else if (Isolation.READ_UNCOMMITTED.equals(isolation)) {
       cc = CursorConfig.READ_UNCOMMITTED;
       lm = LockMode.READ_UNCOMMITTED;
     } else if (Isolation.REPEATABLE_READ.equals(isolation)) {
       // default
     } else if (Isolation.SERIALIZABLE.equals(isolation)) {
       // txn_config
     }
   }
   JE_Cursor je_cursor =
       new JE_Cursor(
           indexMeta, db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm);
   if (txn != null) {
     ((JE_Transaction) txn).addCursor(je_cursor);
   }
   return new SchematicCursor(
       je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta));
 }