@Override public void startObject(long oid, int prevSchemaVersion) { if (posIndex == null) { if (schemaIndexEntry == null) { schemaIndexEntry = schemaIndex.getSchema(def); } posIndex = schemaIndexEntry.getObjectIndexLatestSchemaVersion(); } PagedPosIndex prevIndex = schemaIndexEntry.getObjectIndexVersion(prevSchemaVersion); currentPage = out.getPage(); currentOffs = out.getOffset(); // first remove possible previous position final LongLongIndex.LLEntry objPos = oidIndex.findOidGetLong(oid); if (objPos != null) { long pos = objPos.getValue(); // long with 32=page + 32=offs // prevPos.getValue() returns > 0, so the loop is performed at least once. do { // remove and report to FSM if applicable // TODO // In cache, use separate list for evolved objects to be written (Map<PC/OID, // OriginalClassDef) // Do not put those objects in dirty-list // When checking for dirty (external) return whether contained in dirty-list. // When...??? long nextPos = prevIndex.removePosLongAndCheck(pos); // all secondary pages are marked. nextPos |= PagedPosIndex.MARK_SECONDARY; pos = nextPos; } while (pos != PagedPosIndex.MARK_SECONDARY); } // Update pos index oidIndex.insertLong(oid, currentPage, (int) currentOffs); }
/** Not a true flush, just writes the stuff... */ @Override public final void flush() { // flush associated splits. for (StorageChannelOutput paf : viewsOut) { // flush() only writers paf.flush(); } for (StorageChannelInput paf : viewsIn) { paf.reset(); } try { fc.force(false); } catch (IOException e) { throw DBLogger.newFatal("Error writing database file.", e); } }
@Override public void flush() { out.flush(); // posIndex may change during next transaction due to schema evolution posIndex = null; // setting this to null is important for revert() on failed commits schemaIndexEntry = null; }
public ObjectWriterSV( StorageChannel file, PagedOidIndex oidIndex, ZooClassDef def, SchemaIndex schemaIndex) { this.out = file.getWriter(true); this.oidIndex = oidIndex; out.setOverflowCallbackWrite(this); this.def = def; this.headerForWrite = def.getOid(); this.schemaIndex = schemaIndex; }
@Override public void writeDouble(double double1) { out.writeDouble(double1); }
@Override public void skipWrite(int nBytes) { out.skipWrite(nBytes); }
@Override public void writeLong(long long1) { out.writeLong(long1); }
@Override public void writeShort(short short1) { out.writeShort(short1); }
@Override public void writeFloat(float float1) { out.writeFloat(float1); }
@Override public void writeInt(int int1) { out.writeInt(int1); }
@Override public void writeChar(char char1) { out.writeChar(char1); }
/** This can be necessary when subsequent objects are of a different class. */ @Override public void newPage() { out.allocateAndSeekAP(PAGE_TYPE.DATA, 0, headerForWrite); writeHeader(); }
@Override public void writeByte(byte byte1) { out.writeByte(byte1); }
@Override public void writeBoolean(boolean boolean1) { out.writeBoolean(boolean1); }
@Override public void write(byte[] array) { out.write(array); }
@Override public void writeString(String string) { out.writeString(string); }
private void writeHeader() { out.writeLong(headerForWrite); }