use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OPropertyImpl method setMax.
public OPropertyImpl setMax(final String max) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter property %s max %s", getFullNameQuoted(), quoteString(max));
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter property %s max %s", getFullNameQuoted(), quoteString(max));
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setMaxInternal(max);
} else
setMaxInternal(max);
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OPropertyImpl method setLinkedType.
public OProperty setLinkedType(final OType linkedType) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
checkLinkTypeSupport(getType());
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter property %s linkedtype %s", getFullNameQuoted(), linkedType);
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter property %s linkedtype %s", getFullNameQuoted(), linkedType);
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setLinkedTypeInternal(linkedType);
} else
setLinkedTypeInternal(linkedType);
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OPropertyImpl method setCustom.
public OPropertyImpl setCustom(final String name, final String value) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
acquireSchemaWriteLock();
try {
final String cmd = String.format("alter property %s custom %s=%s", getFullNameQuoted(), name, quoteString(value));
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setCustomInternal(name, value);
} else
setCustomInternal(name, value);
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OCommandExecutorSQLHASyncDatabase method execute.
/**
* Execute the SYNC DATABASE.
*/
public Object execute(final Map<Object, Object> iArgs) {
final ODatabaseDocumentInternal database = getDatabase();
database.checkSecurity(ORule.ResourceGeneric.DATABASE, "sync", ORole.PERMISSION_UPDATE);
final OStorage stg = database.getStorage();
if (!(stg instanceof ODistributedStorage))
throw new ODistributedException("SYNC DATABASE command cannot be executed against a non distributed server");
final ODistributedStorage dStg = (ODistributedStorage) stg;
final OHazelcastPlugin dManager = (OHazelcastPlugin) dStg.getDistributedManager();
if (dManager == null || !dManager.isEnabled())
throw new OCommandExecutionException("OrientDB is not started in distributed mode");
final String databaseName = database.getName();
return dManager.installDatabase(true, databaseName, false, OGlobalConfiguration.DISTRIBUTED_BACKUP_TRY_INCREMENTAL_FIRST.getValueAsBoolean());
}
use of com.orientechnologies.orient.core.storage.OStorage 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;
}
Aggregations