@Override public ORawBuffer readRecord(OStorage storage, ORecordId rid, String fetchPlan, boolean ignoreCache, final int recordVersion) throws ORecordNotFoundException { return storage.readRecordIfVersionIsNotLatest(rid, fetchPlan, ignoreCache, recordVersion).getResult(); } }
protected void callbackHookSuccess(final ORecord record, final boolean wasNew, final byte[] stream, final OStorageOperationResult<Integer> operationResult) { if (stream != null && stream.length > 0) { final ORecordHook.TYPE hookType; if (!operationResult.isMoved()) { hookType = wasNew ? ORecordHook.TYPE.AFTER_CREATE : ORecordHook.TYPE.AFTER_UPDATE; } else { hookType = wasNew ? ORecordHook.TYPE.CREATE_REPLICATED : ORecordHook.TYPE.UPDATE_REPLICATED; } callbackHooks(hookType, record); } }
final OPhysicalPosition ppos; final byte recordType = ORecordInternal.getRecordType(rec); ppos = doCreateRecord(rid, stream, rec.getVersion(), recordType, null, cluster, allocated).getResult(); ORecordInternal.setVersion(rec, updateRes.getResult()); if (updateRes.getModifiedRecordContent() != null) { ORecordInternal.fill(rec, rid, updateRes.getResult(), updateRes.getModifiedRecordContent(), false); ORecordInternal.setVersion(rec, updateRes.getResult()); if (updateRes.getModifiedRecordContent() != null) { ORecordInternal.fill(rec, rid, updateRes.getResult(), updateRes.getModifiedRecordContent(), false);
@Override public final OStorageOperationResult<ORawBuffer> readRecordIfVersionIsNotLatest(final ORecordId rid, final String fetchPlan, final boolean ignoreCache, final int recordVersion) throws ORecordNotFoundException { try { checkOpenness(); return new OStorageOperationResult<>(readRecordIfNotLatest(getClusterById(rid.getClusterId()), rid, recordVersion)); } catch (final RuntimeException ee) { throw logAndPrepareForRethrow(ee); } catch (final Error ee) { throw logAndPrepareForRethrow(ee); } catch (final Throwable t) { throw logAndPrepareForRethrow(t); } }
private OStorageOperationResult<Boolean> doHideMethod(final ORecordId rid, final OCluster cluster) { try { final OPhysicalPosition ppos = cluster.getPhysicalPosition(new OPhysicalPosition(rid.getClusterPosition())); if (ppos == null) { // ALREADY HIDDEN return new OStorageOperationResult<>(false); } makeStorageDirty(); boolean rollback = false; atomicOperationsManager.startAtomicOperation((String) null, true); try { cluster.hideRecord(ppos.clusterPosition); final ORecordSerializationContext context = ORecordSerializationContext.getContext(); if (context != null) { context.executeOperations(this); } } catch (final Exception e) { rollback = true; throw e; } finally { atomicOperationsManager.endAtomicOperation(rollback); } return new OStorageOperationResult<>(true); } catch (final IOException ioe) { OLogManager.instance().error(this, "Error on deleting record " + rid + "( cluster: " + cluster + ")", ioe); throw OException.wrapException(new OStorageException("Error on deleting record " + rid + "( cluster: " + cluster + ")"), ioe); } }
@Override public ORawBuffer readRecord(OStorage storage, ORecordId rid, String fetchPlan, boolean ignoreCache, final int recordVersion) throws ORecordNotFoundException { return storage.readRecord(rid, fetchPlan, ignoreCache, prefetchRecords, null).getResult(); } }
@Override public final OStorageOperationResult<ORawBuffer> readRecord(final ORecordId iRid, final String iFetchPlan, final boolean iIgnoreCache, final boolean prefetchRecords, final ORecordCallback<ORawBuffer> iCallback) { try { checkOpenness(); final OCluster cluster; try { cluster = getClusterById(iRid.getClusterId()); } catch (final IllegalArgumentException e) { throw OException.wrapException(new ORecordNotFoundException(iRid), e); } return new OStorageOperationResult<>(readRecord(cluster, iRid, prefetchRecords)); } catch (final RuntimeException ee) { throw logAndPrepareForRethrow(ee); } catch (final Error ee) { throw logAndPrepareForRethrow(ee); } catch (final Throwable t) { throw logAndPrepareForRethrow(t); } }
@Override public final boolean cleanOutRecord(final ORecordId recordId, final int recordVersion, final int iMode, final ORecordCallback<Boolean> callback) { return deleteRecord(recordId, recordVersion, iMode, callback).getResult(); }
return new OStorageOperationResult<>(recordVersion); return new OStorageOperationResult<>(newRecordVersion, content, false); } else { return new OStorageOperationResult<>(newRecordVersion);
@Override public ORawBuffer call(ODatabaseDocumentInternal database) { return database.getStorage().readRecord(rid, null, true, false, null).getResult(); } });
return new OStorageOperationResult<>(false); return new OStorageOperationResult<>(true); } catch (final IOException ioe) { throw OException
@Override public ORawBuffer call(ODatabaseDocumentInternal database) { return database.getStorage().readRecord(rid2, null, true, false, null).getResult(); } });
return new OStorageOperationResult<>(ppos); } catch (final IOException ioe) { throw OException.wrapException(
byte[] storedContent = storage.readRecord(rid, null, false, false, null).getResult().getBuffer();
private OStorageOperationResult<Integer> doRecycleRecord(final ORecordId rid, final byte[] content, final int version, final OCluster cluster, final byte recordType) { try { makeStorageDirty(); boolean rollback = false; atomicOperationsManager.startAtomicOperation((String) null, true); try { cluster.recycleRecord(rid.getClusterPosition(), content, version, recordType); final ORecordSerializationContext context = ORecordSerializationContext.getContext(); if (context != null) { context.executeOperations(this); } } catch (final Exception e) { rollback = true; throw e; } finally { atomicOperationsManager.endAtomicOperation(rollback); } if (OLogManager.instance().isDebugEnabled()) { OLogManager.instance().debug(this, "Recycled record %s v.%s size=%d", rid, version, content.length); } return new OStorageOperationResult<>(version, content, false); } catch (final IOException ioe) { OLogManager.instance().error(this, "Error on recycling record " + rid + " (cluster: " + cluster + ")", ioe); throw OException .wrapException(new OStorageException("Error on recycling record " + rid + " (cluster: " + cluster + ")"), ioe); } }
@Override public byte[] onUpdate(OStorage storage, byte iRecordType, final ORecordId rid, final int iRecordVersion, final byte[] iRecordContent, final AtomicInteger iDatabaseVersion) { if (iRecordType == ODocument.RECORD_TYPE) { // No need lock, is already inside a lock. Use database to read temporary objects too OStorageOperationResult<ORawBuffer> res = storage.readRecord(rid, null, false, false, null); final ODocument storedRecord = new ODocument(rid).fromStream(res.getResult().getBuffer()); ODocument newRecord = (ODocument) ORecordSaveThreadLocal.getLast(); if (newRecord == null || !newRecord.getIdentity().equals(rid)) newRecord = new ODocument(rid).fromStream(iRecordContent); storedRecord.merge(newRecord, true, true); iDatabaseVersion.set(Math.max(iDatabaseVersion.get(), iRecordVersion) + 1); return storedRecord.toStream(); } else // NO DOCUMENT, CANNOT MERGE SO RELY TO THE VERSION CHECK checkVersions(rid, iRecordVersion, iDatabaseVersion.get()); return null; }
@Override public byte[] onUpdate(OStorage storage, final byte iRecordType, final ORecordId rid, final int iRecordVersion, final byte[] iRecordContent, final AtomicInteger iDatabaseVersion) { final boolean hasSameContent; if (iRecordType == ODocument.RECORD_TYPE) { // No need lock, is already inside a lock. OStorageOperationResult<ORawBuffer> res = storage.readRecord(rid, null, false, false, null); final ODocument storedRecord = new ODocument(rid).fromStream(res.getResult().getBuffer()); final ODocument newRecord = new ODocument().fromStream(iRecordContent); final ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.instance().get(); hasSameContent = ODocumentHelper.hasSameContentOf(storedRecord, currentDb, newRecord, currentDb, null, false); } else { // CHECK BYTE PER BYTE final ORecordAbstract storedRecord = rid.getRecord(); hasSameContent = Arrays.equals(storedRecord.toStream(), iRecordContent); } if (hasSameContent) // OK iDatabaseVersion.set(Math.max(iDatabaseVersion.get(), iRecordVersion)); else // NO DOCUMENT, CANNOT MERGE SO RELY TO THE VERSION CHECK checkVersions(rid, iRecordVersion, iDatabaseVersion.get()); return null; }
/** * This method load the record information by the internal cluster segment. It's for compatibility with older database than * 0.9.25. */ public OStorageConfigurationImpl load(final OContextConfiguration configuration) throws OSerializationException { lock.acquireWriteLock(); try { initConfiguration(configuration); final byte[] record = storage.readRecord(CONFIG_RID, null, false, false, null).getResult().buffer; if (record == null) throw new OStorageException("Cannot load database configuration. The database seems corrupted"); fromStream(record, 0, record.length, streamCharset); } finally { lock.releaseWriteLock(); } return this; }
/** * Execute the command. */ public Object execute(final Map<Object, Object> iArgs) { if (records.isEmpty()) throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet"); int deleted = 0; final ODatabaseDocumentInternal database = getDatabase(); for (String rec : records) { try { final ORecordId rid = new ORecordId(rec); final OStorageOperationResult<Boolean> result = database.getStorage().deleteRecord(rid, -1, 0, null); database.getLocalCache().deleteRecord(rid); if (result.getResult()) deleted++; } catch (Exception e) { throw OException.wrapException(new OCommandExecutionException("Error on executing command"), e); } } return deleted; }