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

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


   * 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;
  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());
           
  } catch (RuntimeException e) {
      throw handleException(
    null, Level.SEVERE, e, "DataStore initialization");
  } catch (Error e) {
      logger.logThrow(
    Level.SEVERE, e, "DataStore initialization failed");
      throw 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

    new Class<?>[] {
        String.class, Properties.class,
        ComponentRegistry.class, TransactionProxy.class },
    directory, properties, systemRegistry, txnProxy);
      boolean txnDone = false;
      DbTransaction txn = env.beginTransaction(Long.MAX_VALUE);
      try {
    Databases dbs = DbUtilities.getDatabases(env, txn, logger);
    infoDb = dbs.info();
    classesDb = dbs.classes();
    oidsDb = dbs.oids();
    namesDb = dbs.names();
    txnDone = true;
    txn.commit();
      } finally {
    if (!txnDone) {
        txn.abort();
    }
      }
      lockManager =
    new MultiLockManager<Object>(lockTimeout, numKeyMaps);
      ServerSocket serverSocket =
View Full Code Here

     */
    @Override
    public long newObjectIds(int numIds) {
  callStarted();
  try {
      DbTransaction txn = env.beginTransaction(txnTimeout);
      boolean txnDone = false;
      try {
    long result = DbUtilities.getNextObjectId(infoDb, txn, numIds);
    txnDone = true;
    txn.commit();
    return result;
      } finally {
    if (!txnDone) {
        txn.abort();
    }
      }
  } finally {
      callFinished();
  }
View Full Code Here

    public GetObjectResults getObject(long nodeId, long oid) {
  NodeInfo nodeInfo = nodeCallStarted(nodeId);
  try {
      checkOid(oid);
      lock(nodeInfo, oid, false, "getObject");
      DbTransaction txn = env.beginTransaction(txnTimeout);
      boolean txnDone = false;
      try {
    byte[] data = oidsDb.get(txn, encodeLong(oid), false);
    txnDone = true;
    txn.commit();
    return (data == null) ? null
        : new GetObjectResults(
      data, getWaiting(oid) == GetWaitingResult.WRITERS);
      } finally {
    if (!txnDone) {
        txn.abort();
    }
      }
  } finally {
      nodeCallFinished(nodeInfo);
  }
View Full Code Here

    {
  NodeInfo nodeInfo = nodeCallStarted(nodeId);
  try {
      checkOid(oid);
      lock(nodeInfo, oid, true, "getObjectForUpdate");
      DbTransaction txn = env.beginTransaction(txnTimeout);
      boolean txnDone = false;
      try {
    byte[] result = oidsDb.get(txn, encodeLong(oid), true);
    txnDone = true;
    txn.commit();
    GetWaitingResult waiters = getWaiting(oid);
    return (result == null) ? null
        : new GetObjectForUpdateResults(
      result, waiters == GetWaitingResult.WRITERS,
      waiters == GetWaitingResult.READERS);
      } finally {
    if (!txnDone) {
        txn.abort();
    }
      }
  } finally {
      nodeCallFinished(nodeInfo);
  }
View Full Code Here

      oid + ", but does not own that object for read");
    logger.logThrow(
        WARNING, exception, "Cache consistency failure");
    throw exception;
      }
      DbTransaction txn = env.beginTransaction(txnTimeout);
      boolean txnDone = false;
      try {
    oidsDb.markForUpdate(txn, encodeLong(oid));
    txnDone = true;
    txn.commit();
      } finally {
    if (!txnDone) {
        txn.abort();
    }
      }
      GetWaitingResult waiting = getWaiting(oid);
      return new UpgradeObjectResults(
    waiting == GetWaitingResult.WRITERS,
View Full Code Here

  try {
      if (oid < -1) {
    throw new IllegalArgumentException(
        "Object ID must not be less than -1");
      }
      DbTransaction txn = env.beginTransaction(txnTimeout);
      boolean txnDone = false;
      NextObjectResults result;
      try {
    DbCursor cursor = oidsDb.openCursor(txn);
    try {
        boolean found = (oid == -1) ? cursor.findFirst()
      : cursor.findNext(encodeLong(oid));
        long nextOid = !found ? -1 : decodeLong(cursor.getKey());
        if (oid != -1 && oid == nextOid) {
      found = cursor.findNext();
      nextOid = !found ? -1 : decodeLong(cursor.getKey());
        }
        result = !found ? null
      : new NextObjectResults(
          nextOid, cursor.getValue(),
          getWaiting(oid) == GetWaitingResult.WRITERS);
    } finally {
        cursor.close();
    }
    txnDone = true;
    txn.commit();
      } finally {
    if (!txnDone) {
        txn.abort();
    }
      }
      if (result != null) {
    lock(nodeInfo, result.oid, false, "nextObjectId");
      }
View Full Code Here

       */
      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

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.