use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class ODistributedTransactionManager method createUndoTasksFromTx.
/**
* Create undo content for distributed 2-phase rollback. This list of undo tasks is sent to all the nodes to revert a transaction
* and it's also applied locally.
*
* @param iTx Current transaction
*
* @return List of remote undo tasks
*/
protected List<OAbstractRemoteTask> createUndoTasksFromTx(final OTransaction iTx) {
final List<OAbstractRemoteTask> undoTasks = new ArrayList<OAbstractRemoteTask>();
for (ORecordOperation op : iTx.getAllRecordEntries()) {
OAbstractRemoteTask undoTask = null;
final ORecord record = op.getRecord();
switch(op.type) {
case ORecordOperation.CREATED:
// CREATE UNDO TASK LATER ONCE THE RID HAS BEEN ASSIGNED
break;
case ORecordOperation.UPDATED:
case ORecordOperation.DELETED:
// CREATE UNDO TASK WITH THE PREVIOUS RECORD CONTENT/VERSION
final ORecordId rid = (ORecordId) record.getIdentity();
final AtomicReference<ORecord> previousRecord = new AtomicReference<ORecord>();
OScenarioThreadLocal.executeAsDefault(new Callable<Object>() {
@Override
public Object call() throws Exception {
final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
final ORecordOperation txEntry = db.getTransaction().getRecordEntry(rid);
if (txEntry != null && txEntry.type == ORecordOperation.DELETED)
// GET DELETED RECORD FROM TX
previousRecord.set(txEntry.getRecord());
else {
final OStorageOperationResult<ORawBuffer> loadedBuffer = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getUnderlying().readRecord(rid, null, true, false, null);
if (loadedBuffer != null) {
// LOAD THE RECORD FROM THE STORAGE AVOIDING USING THE DB TO GET THE TRANSACTIONAL CHANGES
final ORecord loaded = Orient.instance().getRecordFactoryManager().newInstance(loadedBuffer.getResult().recordType);
ORecordInternal.fill(loaded, rid, loadedBuffer.getResult().version, loadedBuffer.getResult().getBuffer(), false);
previousRecord.set(loaded);
} else
// RECORD NOT FOUND ON LOCAL STORAGE, ASK TO DB BECAUSE IT COULD BE SHARDED AND RESIDE ON ANOTHER SERVER
previousRecord.set(db.load(rid));
}
return null;
}
});
if (previousRecord.get() == null)
throw new ORecordNotFoundException(rid);
if (op.type == ORecordOperation.UPDATED)
undoTask = new OFixUpdateRecordTask(previousRecord.get(), ORecordVersionHelper.clearRollbackMode(previousRecord.get().getVersion()));
else
undoTask = new OResurrectRecordTask(previousRecord.get());
break;
default:
continue;
}
if (undoTask != null)
undoTasks.add(undoTask);
}
return undoTasks;
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class ODistributedTransactionManager method createTxTask.
protected OTxTask createTxTask(final List<ORecordOperation> uResult) {
final OTxTask txTask = new OTxTask();
for (ORecordOperation op : uResult) {
final ORecord record = op.getRecord();
final OAbstractRecordReplicatedTask task;
switch(op.type) {
case ORecordOperation.CREATED:
task = new OCreateRecordTask(record);
break;
case ORecordOperation.UPDATED:
task = new OUpdateRecordTask(record);
break;
case ORecordOperation.DELETED:
task = new ODeleteRecordTask(record);
break;
default:
continue;
}
txTask.add(task);
}
return txTask;
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class OCreateRecordTask method forceUpdate.
protected ORecord forceUpdate(final ODistributedServerManager manager, final ODatabaseDocumentInternal database, final ODistributedRequestId requestId, final ORawBuffer loadedRecord) {
// LOAD IT AS RECORD
final ORecord loadedRecordInstance = Orient.instance().getRecordFactoryManager().newInstance(loadedRecord.recordType);
ORecordInternal.fill(loadedRecordInstance, rid, loadedRecord.version, loadedRecord.getBuffer(), false);
// RECORD HAS BEEN ALREADY CREATED (PROBABLY DURING DATABASE SYNC) CHECKING COHERENCY
if (Arrays.equals(loadedRecord.getBuffer(), content))
// SAME CONTENT
return loadedRecordInstance;
ODistributedServerLog.info(this, manager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "Error on creating record in an existent position. toStore=%s stored=%s reqId=%s", getRecord(), loadedRecordInstance, requestId);
throw new ODistributedOperationException("Cannot create the record " + rid + " in an already existent position");
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class OResurrectRecordTask method executeRecordTask.
@Override
public Object executeRecordTask(ODistributedRequestId requestId, final OServer iServer, ODistributedServerManager iManager, final ODatabaseDocumentInternal database) throws Exception {
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "Resurrecting deleted record %s/%s v.%d reqId=%s", database.getName(), rid.toString(), version, requestId);
try {
database.getStorage().recyclePosition(rid, new byte[] {}, version, recordType);
// CREATE A RECORD TO CALL ALL THE HOOKS (LIKE INDEXES FOR UNIQUE CONSTRAINTS)
final ORecord loadedRecordInstance = Orient.instance().getRecordFactoryManager().newInstance(recordType);
ORecordInternal.fill(loadedRecordInstance, rid, version, content, true);
loadedRecordInstance.save();
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "+-> resurrected deleted record");
return Boolean.TRUE;
} catch (OPaginatedClusterException e) {
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "+-> no resurrection, because the record was not deleted");
return Boolean.TRUE;
} catch (Exception e) {
ODistributedServerLog.error(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "+-> error on resurrecting deleted record: the record is already deleted");
}
return Boolean.FALSE;
}
use of com.orientechnologies.orient.core.record.ORecord in project YCSB by brianfrankcooper.
the class OrientDBClient method delete.
@Override
public Status delete(String table, String key) {
while (true) {
try (ODatabaseDocumentTx db = databasePool.acquire()) {
final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
dictionary.remove(key);
return Status.OK;
} catch (OConcurrentModificationException cme) {
continue;
} catch (Exception e) {
e.printStackTrace();
return Status.ERROR;
}
}
}
Aggregations