📄 wizardstore.java
字号:
env.logWriter.newEntry(this, "checking cluster: " + cid + " ...", LogWriter.DEBUG3); } if (!wizardTa.commitClusterIDs.contains(cid)) {// env.logWriter.newEntry( this, "prepare commit cluster: " + cid, LogWriter.DEBUG2 ); wizardTa.commitClusterIDs.add(cid); org.ozoneDB.core.storage.Cluster cluster = clusterStore.loadCluster(cid, true); try { // we don't need to do all the stuff if there is no WRITE // lock if (cluster.lock().level(ta) >= Lock.LEVEL_WRITE) { // delete containers from cluster and // prepare newID and deletedID tables DxIterator it2 = cluster.containers().iterator(); StorageObjectContainer container; while ((container = (StorageObjectContainer) it2.next()) != null) { if (container.isDeleted()) { if (env.logWriter.hasTarget(LogWriter.DEBUG3)) { env.logWriter.newEntry(this, "container deleted: " + container.id(), LogWriter.DEBUG3); } clusterStore.invalidateContainer(container); wizardTa.idTableChanges_push(new IDTableChange(container.id(), cid, IDTableChange.STATE_REMOVED)); if (container.name() != null) { wizardTa.nameTableChanges_push(new NameTableChange(container.id(), container.name(), NameTableChange.STATE_REMOVED)); } } container.clearState(); } } } finally { if (cluster instanceof WizardCluster) { ((WizardCluster)cluster).unpin(); } } clusterStore.prepareCommitCluster(ta, cid); } } } protected boolean isCleanShutdown() { return !(new File(COMMIT_FLAG_NAME).exists()); } protected void beginCommit(Transaction ta) throws IOException {// env.logWriter.newEntry( this, "beginCommit...", LogWriter.DEBUG2 ); // do nothing if this was just a read transaction if (ta.maxLockLevel() < Lock.LEVEL_WRITE) { return; } int commitCount = 0; // read the current commitCount from file File f = new File(env.getDatabaseDir() + COMMIT_FLAG_NAME); if (f.exists()) { DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(f)); commitCount = in.readInt(); } finally { if (in != null) { in.close(); } } } commitCount++; DataOutputStream out = null; try { out = new DataOutputStream(new FileOutputStream(f)); out.writeInt(commitCount); } finally { if (out != null) { out.close(); } } } protected void endCommit(Transaction ta) throws IOException {// env.logWriter.newEntry( this, "endCommit...", LogWriter.DEBUG2 ); // do nothing if this was just a read transaction if (ta.maxLockLevel() < Lock.LEVEL_WRITE) { return; } int commitCount = 0; // read the current commitCount from file File f = new File(env.getDatabaseDir() + COMMIT_FLAG_NAME); if (f.exists()) { DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(f)); commitCount = in.readInt(); } finally { if (in != null) { in.close(); } } } else { throw new RuntimeException("No commit flag file present."); } commitCount--; if (commitCount > 0) { DataOutputStream out = null; try { out = new DataOutputStream(new FileOutputStream(f)); out.writeInt(commitCount); } finally { if (out != null) { out.close(); } } } else { if (!(f.delete())) { throw new RuntimeException("Unable to delete commit flag file. "); } } } public synchronized void commitTransaction(Transaction ta) throws IOException, ClassNotFoundException { if (env.logWriter.hasTarget(LogWriter.DEBUG3)) { env.logWriter.newEntry(this, "commitTransaction()", LogWriter.DEBUG3); } beginCommit(ta); WizardTransaction wizardTa = (WizardTransaction) ta; // actually write changed clusters to disk DxSet commitClusterIDs = wizardTa.commitClusterIDs; DxIterator it = commitClusterIDs.iterator(); ClusterID cid; while ((cid = (ClusterID) it.next()) != null) { if (env.logWriter.hasTarget(LogWriter.DEBUG2)) { env.logWriter.newEntry(this, "commit cluster: " + cid, LogWriter.DEBUG2); } clusterStore.commitCluster(ta, cid); } // update global idTable boolean isIDTableChanged = false; IDTableChange idChange = null; while ((idChange = wizardTa.idTableChanges_pop()) != null) { isIDTableChanged = true; switch (idChange.state) { case IDTableChange.STATE_ADDED: {// env.logWriter.newEntry( this, "commit added oid: " + idChange.oid, LogWriter.DEBUG2 ); if (idTable.addForKey(idChange.cid, idChange.oid) == false) { throw new IllegalStateException("Unable to add OID to global ID table."); } break; } case IDTableChange.STATE_REMOVED: { if (false) { env.logWriter.newEntry(this, "commit removed oid: " + idChange.oid, LogWriter.DEBUG2); } if (idTable.removeForKey(idChange.oid) == null) { throw new IllegalStateException("Unable to remove OID from global ID table."); } break; } default: { throw new RuntimeException("ID change table entry has inproper state."); } } } // write changes to disk if (isIDTableChanged) { commitIDTable(); } // update global nameTable boolean isNameTableChanged = false; NameTableChange nameChange = wizardTa.nameTableChanges_pop(); while (nameChange != null) { isNameTableChanged = true; switch (nameChange.state) { case NameTableChange.STATE_ADDED: { nameTable.addForKey(nameChange.oid, nameChange.name); break; } case NameTableChange.STATE_REMOVED: { nameTable.removeForKey(nameChange.name); break; } default: { throw new RuntimeException("Name change table entry has inproper state."); } } nameChange = wizardTa.nameTableChanges_pop(); } // write changes to disk if (isNameTableChanged) { commitNameTable(); } endCommit(ta); if (env.logWriter.hasTarget(LogWriter.DEBUG2)) { env.logWriter.newEntry(this, " idTable.count(): " + idTable.count(), LogWriter.DEBUG2); env.logWriter.newEntry(this, " nameTable.count(): " + nameTable.count(), LogWriter.DEBUG2); } } /** * @param ta ID of the comitting transaction. */ public synchronized void abortTransaction(Transaction ta) throws IOException, ClassNotFoundException { if (env.logWriter.hasTarget(LogWriter.DEBUG3)) { env.logWriter.newEntry(this, "abortTransaction()", LogWriter.DEBUG3); } WizardTransaction wizardTa = (WizardTransaction) ta; wizardTa.commitClusterIDs = new DxHashSet(64); DxIterator it = wizardTa.idTable.iterator(); ClusterID cid; while ((cid = (ClusterID) it.next()) != null) { if (!wizardTa.commitClusterIDs.contains(cid)) { // We MUST NOT abort read locked clusters (because they may be read locked from other transactions, too) org.ozoneDB.core.storage.Cluster cluster = clusterStore.loadCluster(cid, true); if (cluster.lock().level(ta) > Lock.LEVEL_READ) { if (env.logWriter.hasTarget(LogWriter.DEBUG2)) { env.logWriter.newEntry(this, "abort cluster: " + cid, LogWriter.DEBUG2); } clusterStore.abortCluster(ta, cid); } else { // Do a plain unlock, and we are fine. cluster.lock().release(ta); } wizardTa.commitClusterIDs.add(cid); } } } /** Tells this StoreManager to report every named object to the garbage collector. */ public void reportNamedObjectsToGarbageCollector() { synchronized (this) { DxIterator i = nameTable.elementSet().iterator(); while (i.next() != null) { garbageCollector.notifyNamedObject((ObjectID) i.object()); } } } public Transaction createTransaction(Env env, User user) { return new WizardTransaction(env, user); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -