use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class LRUListTest method testAddThreePutMiddleToTopChangePointer.
@Test
public void testAddThreePutMiddleToTopChangePointer() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
ByteBuffer bufferOne = bufferPool.acquireDirect(true);
ByteBuffer bufferTwo = bufferPool.acquireDirect(true);
ByteBuffer bufferThree = bufferPool.acquireDirect(true);
ByteBuffer bufferFour = bufferPool.acquireDirect(true);
OCachePointer cachePointerOne = new OCachePointer(bufferOne, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCachePointer cachePointerTwo = new OCachePointer(bufferTwo, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCachePointer cachePointerThree = new OCachePointer(bufferThree, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCachePointer cachePointerFour = new OCachePointer(bufferFour, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
lruList.putToMRU(new OCacheEntry(1, 10, cachePointerOne, false));
lruList.putToMRU(new OCacheEntry(1, 20, cachePointerTwo, false));
lruList.putToMRU(new OCacheEntry(3, 30, cachePointerThree, false));
lruList.putToMRU(new OCacheEntry(1, 20, cachePointerFour, false));
Assert.assertEquals(lruList.size(), 3);
Iterator<OCacheEntry> entryIterator = lruList.iterator();
Assert.assertTrue(entryIterator.hasNext());
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 20, cachePointerFour, false));
Assert.assertEquals(entryIterator.next(), new OCacheEntry(3, 30, cachePointerThree, false));
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 10, cachePointerOne, false));
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class LRUListTest method testAddThree.
@Test
public void testAddThree() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
ByteBuffer bufferOne = bufferPool.acquireDirect(true);
ByteBuffer bufferTwo = bufferPool.acquireDirect(true);
ByteBuffer bufferThree = bufferPool.acquireDirect(true);
OCachePointer cachePointerOne = new OCachePointer(bufferOne, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCachePointer cachePointerTwo = new OCachePointer(bufferTwo, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCachePointer cachePointerThree = new OCachePointer(bufferThree, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
lruList.putToMRU(new OCacheEntry(1, 10, cachePointerOne, false));
lruList.putToMRU(new OCacheEntry(1, 20, cachePointerTwo, false));
lruList.putToMRU(new OCacheEntry(3, 30, cachePointerThree, false));
Assert.assertEquals(lruList.size(), 3);
Iterator<OCacheEntry> entryIterator = lruList.iterator();
Assert.assertTrue(entryIterator.hasNext());
Assert.assertEquals(entryIterator.next(), new OCacheEntry(3, 30, cachePointerThree, false));
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 20, cachePointerTwo, false));
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 10, cachePointerOne, false));
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class LRUListTest method testAdd9128.
@Test
public void testAdd9128() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
OCachePointer[] cachePointers = new OCachePointer[9128];
for (int i = 0; i < 9128; i++) {
ByteBuffer buffer = bufferPool.acquireDirect(true);
cachePointers[i] = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
lruList.putToMRU(new OCacheEntry(1, i * 10, cachePointers[i], false));
}
Assert.assertEquals(lruList.size(), 9128);
Iterator<OCacheEntry> entryIterator = lruList.iterator();
for (int i = 9127; i >= 0; i--) {
Assert.assertTrue(entryIterator.hasNext());
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, i * 10, cachePointers[i], false));
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class OSyncDatabaseDeltaTask method deltaBackup.
protected Object deltaBackup(final ODistributedRequestId requestId, final ODistributedServerManager iManager, final ODatabaseDocumentInternal database, final String databaseName) throws IOException, InterruptedException {
final Long lastDeployment = (Long) iManager.getConfigurationMap().get(DEPLOYDB + databaseName);
if (lastDeployment != null && lastDeployment.longValue() == random) {
// SKIP IT
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.NONE, "Skip deploying delta database '%s' because already executed", databaseName);
return Boolean.FALSE;
}
iManager.getConfigurationMap().put(DEPLOYDB + databaseName, random);
final ODistributedDatabase dDatabase = checkIfCurrentDatabaseIsNotOlder(iManager, databaseName, startLSN);
iManager.setDatabaseStatus(getNodeSource(), databaseName, ODistributedServerManager.DB_STATUS.SYNCHRONIZING);
ODistributedServerLog.info(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.OUT, "Deploying database '%s' with delta of changes...", databaseName);
// CREATE A BACKUP OF DATABASE
final File backupFile = new File(Orient.getTempPath() + "/backup_" + getNodeSource() + "_" + database.getName() + ".zip");
ODistributedServerLog.info(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.OUT, "Creating delta backup of database '%s' (startLSN=%s) in directory: %s...", databaseName, startLSN, backupFile.getAbsolutePath());
if (backupFile.exists())
backupFile.delete();
else
backupFile.getParentFile().mkdirs();
backupFile.createNewFile();
final FileOutputStream fileOutputStream = new FileOutputStream(backupFile);
// final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream);
final File completedFile = new File(backupFile.getAbsolutePath() + ".completed");
if (completedFile.exists())
completedFile.delete();
final OStorage storage = database.getStorage().getUnderlying();
if (!(storage instanceof OAbstractPaginatedStorage))
throw new UnsupportedOperationException("Storage '" + storage.getName() + "' does not support distributed delta backup");
final AtomicReference<OLogSequenceNumber> endLSN = new AtomicReference<OLogSequenceNumber>();
final AtomicReference<ODistributedDatabaseDeltaSyncException> exception = new AtomicReference<ODistributedDatabaseDeltaSyncException>();
try {
final AtomicLong counter = new AtomicLong(0);
endLSN.set(((OAbstractPaginatedStorage) storage).recordsChangedAfterLSN(startLSN, fileOutputStream, excludedClusterNames, new OCommandOutputListener() {
@Override
public void onMessage(final String iText) {
if (iText.startsWith("read")) {
if (counter.incrementAndGet() % 100000 == 0) {
ODistributedServerLog.info(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.OUT, "- %s", iText);
}
} else if (counter.incrementAndGet() % 10000 == 0) {
ODistributedServerLog.info(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.OUT, "- %s", iText);
}
}
}));
if (endLSN.get() == null) {
// DELTA NOT AVAILABLE, TRY WITH FULL BACKUP
exception.set(new ODistributedDatabaseDeltaSyncException(startLSN));
} else
ODistributedServerLog.info(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.OUT, "Delta backup of database '%s' completed. range=%s-%s", databaseName, startLSN, endLSN.get());
} catch (Exception e) {
// UNKNOWN ERROR, DELTA NOT AVAILABLE, TRY WITH FULL BACKUP
exception.set(new ODistributedDatabaseDeltaSyncException(startLSN, e.getMessage()));
} finally {
try {
fileOutputStream.close();
} catch (IOException e) {
}
try {
completedFile.createNewFile();
} catch (IOException e) {
OLogManager.instance().error(this, "Cannot create file of delta backup completed: %s", e, completedFile);
}
}
if (exception.get() instanceof ODistributedDatabaseDeltaSyncException) {
throw exception.get();
}
ODistributedServerLog.info(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.OUT, "Deploy delta database task completed");
// GET THE MOMENTUM, BUT OVERWRITE THE LAST LSN RECEIVED FROM THE DELTA
final ODistributedMomentum momentum = dDatabase.getSyncConfiguration().getMomentum().copy();
momentum.setLSN(iManager.getLocalNodeName(), endLSN.get());
final ODistributedDatabaseChunk chunk = new ODistributedDatabaseChunk(backupFile, 0, CHUNK_MAX_SIZE, momentum, false);
ODistributedServerLog.info(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.OUT, "- transferring chunk #%d offset=%d size=%s...", 1, 0, OFileUtils.getSizeAsNumber(chunk.buffer.length));
if (chunk.last)
// NO MORE CHUNKS: SET THE NODE ONLINE (SYNCHRONIZING ENDED)
iManager.setDatabaseStatus(iManager.getLocalNodeName(), databaseName, ODistributedServerManager.DB_STATUS.ONLINE);
return chunk;
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class OSyncDatabaseDeltaTask method fromStream.
@Override
public void fromStream(final DataInput in, final ORemoteTaskFactory factory) throws IOException {
startLSN = new OLogSequenceNumber(in);
lastOperationTimestamp = in.readLong();
random = in.readLong();
excludedClusterNames.clear();
final int total = in.readInt();
for (int i = 0; i < total; ++i) {
excludedClusterNames.add(in.readUTF());
}
}
Aggregations