Package com.sun.sgs.service.store.db

Examples of com.sun.sgs.service.store.db.DbTransaction


      BindingKey key = null;
      for (int i = 0; true; i++) {
    if (i > MAX_RANGE_LOCK_RETRIES) {
        throw new ResourceUnavailableException("Too many retries");
    }
    DbTransaction txn = env.beginTransaction(txnTimeout);
    boolean txnDone = false;
    String nextName;
    boolean found;
    long oid;
    try {
        DbCursor cursor = namesDb.openCursor(txn);
        try {
      boolean hasNext = cursor.findNext(encodeString(name));
      nextName =
          hasNext ? decodeString(cursor.getKey()) : null;
      found = hasNext && name.equals(nextName);
      oid = hasNext ? decodeLong(cursor.getValue()) : -1;
        } finally {
      cursor.close();
        }
        txnDone = true;
        txn.commit();
    } finally {
        if (!txnDone) {
      txn.abort();
        }
    }
    if (results != null &&
        found == results.found &&
        safeEquals(found ? null : nextName, results.nextName))
View Full Code Here


      BindingKey nextNameKey = null;
      for (int i = 0; true; i++) {
    if (i > MAX_RANGE_LOCK_RETRIES) {
        throw new ResourceUnavailableException("Too many retries");
    }
    DbTransaction txn = env.beginTransaction(txnTimeout);
    boolean txnDone = false;
    String nextName;
    long oid;
    long nextOid;
    try {
        DbCursor cursor = namesDb.openCursor(txn);
        try {
      boolean hasNext = cursor.findNext(encodeString(name));
      nextName =
          hasNext ? decodeString(cursor.getKey()) : null;
      if (hasNext && name.equals(nextName)) {
          oid = decodeLong(cursor.getValue());
          /* Move to name after matching name */
          hasNext = cursor.findNext();
          nextName =
        hasNext ? decodeString(cursor.getKey()) : null;
      } else {
          oid = -1;
      }
      nextOid = hasNext ? decodeLong(cursor.getValue()) : -1;
        } finally {
      cursor.close();
        }
        txnDone = true;
        txn.commit();
    } finally {
        if (!txnDone) {
      txn.abort();
        }
    }
    boolean found = (oid != -1);
    if (results != null &&
        found == results.found &&
View Full Code Here

      BindingKey nextNameKey = null;
      for (int i = 0; true; i++) {
    if (i > MAX_RANGE_LOCK_RETRIES) {
        throw new ResourceUnavailableException("Too many retries");
    }
    DbTransaction txn = env.beginTransaction(txnTimeout);
    boolean txnDone = false;
    long oid;
    String nextName;
    try {
        DbCursor cursor = namesDb.openCursor(txn);
        try {
      boolean hasNext = (name == null) ? cursor.findFirst()
          : cursor.findNext(encodeString(name));
      nextName =
          hasNext ? decodeString(cursor.getKey()) : null;
      if ((name != null) && name.equals(nextName)) {
          hasNext = cursor.findNext();
          nextName = (hasNext)
        ? decodeString(cursor.getKey()) : null;
      }
      oid = hasNext ? decodeLong(cursor.getValue()) : -1;
        } finally {
      cursor.close();
        }
        txnDone = true;
        txn.commit();
    } finally {
        if (!txnDone) {
      txn.abort();
        }
    }
    if (results != null &&
        safeEquals(nextName, results.nextName))
    {
View Full Code Here

        int newOids,
        String[] names,
        long[] nameValues)
  throws CacheConsistencyException
    {
  DbTransaction txn = env.beginTransaction(txnTimeout);
  boolean txnDone = false;
  try {
      for (int i = 0; i < oids.length; i++) {
    long oid = oids[i];
    if (oid < 0) {
        throw new IllegalArgumentException(
      "The object IDs must not be negative");
    }
    if (i < newOids) {
        lock(nodeInfo, oid, true, "commit");
    } else {
        checkLocked(nodeInfo, oid, true);
    }
    byte[] value = oidValues[i];
    if (value == null) {
        oidsDb.delete(txn, encodeLong(oid));
    } else {
        oidsDb.put(txn, encodeLong(oid), oidValues[i]);
    }
      }
      DbCursor cursor = namesDb.openCursor(txn);
      try {
    for (int i = 0; i < names.length; i++) {
        String name = names[i];
        if (name == null) {
      throw new IllegalArgumentException(
          "The names must not be null");
        }
        long value = nameValues[i];
        if (value < -1) {
      throw new IllegalArgumentException(
          "The name values must not be less than -1");
        }
        String nextName = cursor.findNext(encodeString(name))
      ? decodeString(cursor.getKey()) : null;
        BindingKey nextKey = BindingKey.getAllowLast(nextName);
        if (value != -1) {
      /* Set -- next name must be write locked */
      checkLocked(nodeInfo, nextKey, true);
      if (!name.equals(nextName)) {
          lock(nodeInfo, BindingKey.get(name), true,
         "commit");
      }
      namesDb.put(
          txn, encodeString(name), encodeLong(value));
        } else if (!name.equals(nextName)) {
      /* Already removed -- next name must be read locked */
      checkLocked(nodeInfo, nextKey, false);
        } else {
      /* Remove -- name and next name must be write locked */
      checkLocked(nodeInfo, nextKey, true);
      checkLocked(nodeInfo,
            BindingKey.getAllowLast(
          cursor.findNext() ?
          decodeString(cursor.getKey()) : null),
            true);
      namesDb.delete(txn, encodeString(name));
      releaseLock(nodeInfo, nextKey, "commit");
        }
    }
      } finally {
    cursor.close();
      }
      txnDone = true;
      txn.commit();
  } finally {
      if (!txnDone) {
    txn.abort();
      }
  }
    }
View Full Code Here

     * @return  the new node ID
     */
    private long getNextNodeId() {
  synchronized (nextNodeIdSync) {
      if (nextNodeId > lastNodeId) {
    DbTransaction txn = env.beginTransaction(txnTimeout);
    boolean txnDone = false;
    try {
        nextNodeId = DbUtilities.getNextNodeId(
      infoDb, txn, NODE_ID_ALLOCATION_BLOCK_SIZE);
        txnDone = true;
        txn.commit();
    } finally {
        if (!txnDone) {
      txn.abort();
        }
    }
    lastNodeId = nextNodeId + NODE_ID_ALLOCATION_BLOCK_SIZE - 1;
      }
      return nextNodeId++;
View Full Code Here

   * Use an absolute path to avoid problems on Windows.
   * -tjb@sun.com (02/16/2007)
   */
  directory = new File(specifiedDirectory).getAbsolutePath();
  txnInfoTable = getTxnInfoTable(TxnInfo.class);
  DbTransaction dbTxn = null;
  boolean done = false;
  Throwable exception;
  try {
      File directoryFile = new File(specifiedDirectory).getAbsoluteFile();
            if (!directoryFile.exists()) {
                logger.log(Level.INFO, "Creating database directory : " +
                           directoryFile.getAbsolutePath());
                if (!directoryFile.mkdirs()) {
                    throw new DataStoreException("Unable to create database " +
                                                 "directory : " +
                                                 directoryFile.getName());
                }
      }
            env = wrappedProps.getClassInstanceProperty(
                    ENVIRONMENT_CLASS_PROPERTY,
                    DEFAULT_ENVIRONMENT_CLASS,
                    DbEnvironment.class,
                    new Class<?>[]{
                        String.class, Properties.class,
      ComponentRegistry.class, TransactionProxy.class
                    },
                    directory, properties, systemRegistry, txnProxy);
      dbTxn = env.beginTransaction(Long.MAX_VALUE);
      Databases dbs = DbUtilities.getDatabases(env, dbTxn, logger);
      infoDb = dbs.info();
      classesDb = dbs.classes();
      oidsDb = dbs.oids();
      namesDb = dbs.names();
      nodeId = DataStoreHeader.getNextId(
    DataStoreHeader.NEXT_NODE_ID_KEY, infoDb, dbTxn, 1);
      useAllocationBlockPlaceholders =
    env.useAllocationBlockPlaceholders();
      freeObjectIds = new FreeObjectIds(useAllocationBlockPlaceholders);
      removeUnusedAllocationPlaceholders(dbTxn);
      done = true;
      dbTxn.commit();
            logger.log(Level.CONFIG,
                       "Created DataStoreImpl with properties:" +
                       "\n  " + DIRECTORY_PROPERTY + "=" + specifiedDirectory +
                       "\n  " + ENVIRONMENT_CLASS_PROPERTY + "=" +
                       env.getClass().getName());
      return;
  } catch (RuntimeException e) {
      exception = e;
  } catch (Error e) {
      exception = e;
  } finally {
      if (dbTxn != null && !done) {
    try {
        dbTxn.abort();
    } catch (RuntimeException e) {
        logger.logThrow(Level.FINE, e, "Exception during abort");
    }
      }
  }
View Full Code Here

  ObjectIdInfo objectIdInfo = txnInfo.getObjectIdInfo();
  if (objectIdInfo == null) {
      logger.log(Level.FINE, "Allocate more object IDs");
      long newNextObjectId;
      long newLastObjectId;
      DbTransaction dbTxn = env.beginTransaction(txn.getTimeout());
      boolean done = false;
      try {
    newNextObjectId = DbUtilities.getNextObjectId(
        infoDb, dbTxn, ALLOCATION_BLOCK_SIZE);
    newLastObjectId =
        newNextObjectId + ALLOCATION_BLOCK_SIZE - 1;
    maybeUpdateAllocationBlockPlaceholders(
        dbTxn, newLastObjectId);
    done = true;
    dbTxn.commit();
      } finally {
    if (!done) {
        dbTxn.abort();
    }
      }
      objectIdInfo = txnInfo.createObjectIdInfo(
    newNextObjectId, newLastObjectId);
  }
View Full Code Here

     * Returns the next available ID stored under the specified key, and
     * increments the stored value by the specified amount.  Uses the specified
     * timeout when creating a DB transaction.
     */
    private long getNextId(long key, int blockSize, long timeout) {
  DbTransaction dbTxn = env.beginTransaction(timeout);
  boolean done = false;
  try {
      long id = DataStoreHeader.getNextId(
    key, infoDb, dbTxn, blockSize);
      done = true;
      dbTxn.commit();
      return id;
  } finally {
      if (!done) {
    dbTxn.abort();
      }
  }
    }
View Full Code Here

TOP

Related Classes of com.sun.sgs.service.store.db.DbTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.