Package com.sleepycat.je

Examples of com.sleepycat.je.DatabaseException


        checkState(false);
        try {
            long commitLsn = DbLsn.NULL_LSN;
            synchronized (this) {
                if (checkCursorsForClose()) {
                    throw new DatabaseException
                        ("Transaction " + id +
                         " commit failed because there were open cursors.");
                }

                /* Transfer handle locks to their owning handles. */
                if (handleLockToHandleMap != null) {
                    Iterator handleLockIter =
                        handleLockToHandleMap.entrySet().iterator();
                    while (handleLockIter.hasNext()){
                        Map.Entry entry = (Map.Entry) handleLockIter.next();
                        transferHandleLockToHandleSet((Long) entry.getKey(),
                                                      (Set) entry.getValue());
                    }
                }

                LogManager logManager = envImpl.getLogManager();

                /*
                 * Release all read locks, clear lock collection. Optimize for
                 * the case where there are no read locks.
                 */
                int numReadLocks = clearReadLocks();

                /*
                 * Log the commit if we ever held any write locks. Note that
                 * with dbhandle write locks, we may have held the write lock
                 * but then had it transferred away.
                 */
                int numWriteLocks = 0;
                if (writeInfo != null) {
                    numWriteLocks = writeInfo.size();
                    TxnCommit commitRecord =
                        new TxnCommit(id, lastLoggedLsn);
        if (flushSyncBehavior == TXN_SYNC) {
      /* Flush and sync required. */
      commitLsn = logManager.
          logForceFlush(commitRecord, true);
        } else if (flushSyncBehavior == TXN_WRITE_NOSYNC) {
      /* Flush but no sync required. */
      commitLsn = logManager.
          logForceFlush(commitRecord, false);
        } else {
      /* No flush, no sync required. */
      commitLsn = logManager.log(commitRecord);
        }
               
                    /*
                     * Used to prevent double counting abortLNS if there is
                     * more then one node with the same abortLSN in this txn.
                     * Two nodes with the same abortLSN occur when a deleted
                     * slot is reused in the same txn.
                     */
                    Set alreadyCountedLsnSet = new HashSet();

                    /* Release all write locks, clear lock collection. */
                    Iterator iter = writeInfo.values().iterator();
                    while (iter.hasNext()) {
                        WriteLockInfo info = (WriteLockInfo) iter.next();
                        lockManager.release(info.lock, this);

                        /*
                         * Count the abortLSN as obsolete.  Do not count if a
                         * slot with a deleted LN was reused
                         * (abortKnownDeleted), to avoid double counting.
                         */
                        if (info.abortLsn != DbLsn.NULL_LSN &&
                            !info.abortKnownDeleted) {
                            Long longLsn = new Long(info.abortLsn);
                            if (!alreadyCountedLsnSet.contains(longLsn)) {
                                logManager.countObsoleteNode
                                    (info.abortLsn, null);
                                alreadyCountedLsnSet.add(longLsn);
                            }
                        }
                    }
                    writeInfo = null;

                    /* Unload delete info, but don't wake up the compressor. */
                    if ((deleteInfo != null) && deleteInfo.size() > 0) {
                        envImpl.addToCompressorQueue(deleteInfo.values(),
                                                     false); // don't wakeup
                        deleteInfo.clear();
                    }

        cleanupDatabaseImpls(true);
                }

                traceCommit(numWriteLocks, numReadLocks);
            }

            /*
             * Unregister this txn. Be sure to do this outside the
             * synchronization block, to avoid conflict w/checkpointer.
             */
            close(true);
            return commitLsn;
        } catch (RunRecoveryException e) {

            /* May have received a thread interrupt. */
            throw e;
        } catch (Throwable t) {

            try {

    /*
     * If the exception thrown is a DatabaseException it indicates
     * that the write() call hit an IOException, probably out of
     * disk space, and attempted to rewrite all commit records as
     * abort records.  Since the abort records are already
     * rewritten (or at least attempted to be rewritten), there is
     * no reason to have abort attempt to write an abort record
     * again.  See [11271].
     */
                abortInternal(flushSyncBehavior == TXN_SYNC,
            !(t instanceof DatabaseException));
                Tracer.trace(envImpl, "Txn", "commit",
                             "Commit of transaction " + id + " failed", t);
            } catch (Throwable abortT2) {
                throw new DatabaseException
                    ("Failed while attempting to commit transaction " +
                     id +
                     ". The attempt to abort and clean up also failed. " +
                     "The original exception seen from commit = " +
                     t.getMessage() +
                     " The exception from the cleanup = " +
                     abortT2.getMessage(),
                     t);
            }
               
            /* Now throw an exception that shows the commit problem. */
            throw new DatabaseException
                ("Failed while attempting to commit transaction " + id +
                 ", aborted instead. Original exception = " +
                 t.getMessage(), t);
        }
    }
View Full Code Here


                             "Abort:id = " + id +
                             " numWriteLocks= " + numWriteLocks +
                             " numReadLocks= " + numReadLocks +
                             " openCursors= " + openCursors);
                if (openCursors) {
                    throw new DatabaseException
                        ("Transaction " + id +
                         " detected open cursors while aborting");
                }
                /* Unload any db handles protected by this txn. */
                if (handleToHandleLockMap != null) {
View Full Code Here

  if (!calledByAbort && onlyAbortable) {

      /*
       * It's ok for FindBugs to whine about id not being synchronized.
       */
            throw new DatabaseException
    ("Transaction " + id + " must be aborted.");
  }

  if (ok ||
      (calledByAbort && onlyAbortable)) {
      return;
  }

  /*
   * It's ok for FindBugs to whine about id not being synchronized.
   */
  throw new DatabaseException
      ("Transaction " + id + " has been closed.");
    }
View Full Code Here

            idCursor = new CursorImpl(idDatabase, autoTxn);
            idCursor.setAllowEviction(allowEviction);
            idCursor.putLN(newId.getBytes(), new MapLN(newDb), false);
            operationOk = true;
  } catch (UnsupportedEncodingException UEE) {
      throw new DatabaseException(UEE);
        } finally {
            if (idCursor != null) {
                idCursor.close();
            }
View Full Code Here

      boolean searchOk = (cursor.searchAndPosition
              (keyDbt, new DatabaseEntry(),
               SearchMode.SET, LockType.WRITE) &
              CursorImpl.FOUND) != 0;
      if (!searchOk) {
                            throw new DatabaseException(
                                "can't find database " + db.getId());
                        }
      mapLN = (MapLN)
          cursor.getCurrentLNAlreadyLatched(LockType.WRITE);
                        assert mapLN != null; /* Should be locked. */
 
View Full Code Here

             * other transactions can open. XXX, another handle using the same
             * txn could open ...
             */
            int handleCount = result.dbImpl.getReferringHandleCount();
            if (handleCount > 0) {
                throw new DatabaseException("Can't " + action + " database " +
                                            databaseName + "," + handleCount +
                                            " open Dbs exist");
            }
  } catch (UnsupportedEncodingException UEE) {
            result.nameCursor.releaseBIN();
            result.nameCursor.close();
      throw new DatabaseException(UEE);
        } catch (DatabaseException e) {
            result.nameCursor.releaseBIN();
            result.nameCursor.close();
      throw e;
        }
View Full Code Here

                                 new NameLN(result.dbImpl.getId()), false);
                result.dbImpl.setDebugDatabaseName(newName);
                return true;
            }
  } catch (UnsupportedEncodingException UEE) {
      throw new DatabaseException(UEE);
        } finally {
            if (nameCursor != null) {
                nameCursor.releaseBIN();
                nameCursor.close();
            }
View Full Code Here

                return recordCount;
            }

  } catch (CloneNotSupportedException CNSE) {
      throw new DatabaseException(CNSE);
        } finally {
            if (nameCursor != null) {
                nameCursor.releaseBIN();
                nameCursor.close();
            }
View Full Code Here

                /*
                 * Should be found, since truncate is instigated from
                 * Database.truncate();
                 */
                throw new DatabaseException
                    ("Database " + databaseName +  " not found in map tree");
            }

            /* Call getCurrentLN to write lock the nameLN. */
            NameLN nameLN = (NameLN)
                nameCursor.getCurrentLNAlreadyLatched(LockType.WRITE);
            assert nameLN != null; /* Should be locked. */

            /*
             * Check the open handle count after we have the write lock and no
             * other transactions can open. XXX, another handle using the same
             * txn could open ...
             */
            int handleCount = oldDatabase.getReferringHandleCount();
            if (handleCount > 1) {
                throw new DatabaseException("Can't truncate database " +
              databaseName + "," + handleCount +
              " open databases exist");
            }
           
            /*
             * Make a new database with an empty tree. Make the nameLN refer to
             * the id of the new database.
             */
            DatabaseImpl newDb;
            DatabaseId newId = new DatabaseId(getNextDbId());
      newDb = (DatabaseImpl) oldDatabase.clone();
            newDb.setId(newId);
            newDb.setTree(new Tree(newDb));
           
            /* Insert the new db into id -> name map */
            CursorImpl idCursor = null;
            boolean operationOk = false;
            AutoTxn autoTxn = null;
            try {
                autoTxn = new AutoTxn(envImpl, new TransactionConfig());
                idCursor = new CursorImpl(idDatabase, autoTxn);
                idCursor.putLN(newId.getBytes(),
             new MapLN(newDb), false);
                operationOk = true;
            } finally {
                if (idCursor != null) {
                    idCursor.close();
                }

                if (autoTxn != null) {
                    autoTxn.operationEnd(operationOk);
                }
            }
            nameLN.setId(newDb.getId());

            /* Record utilization profile changes for the deleted database. */
            int recordCount = oldDatabase.recordObsoleteNodes();

            /* Schedule database for final deletion during commit. */
            locker.markDeleteAtTxnEnd(oldDatabase,
                                      true,
                                      envImpl.getMemoryBudget());

            /* log the nameLN. */
            DatabaseEntry dataDbt = new DatabaseEntry(new byte[0]);
            nameCursor.putCurrent(dataDbt, null, null);
            return new TruncateResult(newDb, recordCount);
  } catch (CloneNotSupportedException CNSE) {
      throw new DatabaseException(CNSE);
  } catch (UnsupportedEncodingException UEE) {
      throw new DatabaseException(UEE);
        } finally {
            nameCursor.releaseBIN();
            nameCursor.close();
        }
    }
View Full Code Here

                return null;
            } else {
                return getDb(id, -1, allowEviction, databaseName);
            }
  } catch (UnsupportedEncodingException UEE) {
      throw new DatabaseException(UEE);
        }
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.DatabaseException

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.