Search in sources :

Example 26 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OServer method openDatabase.

public ODatabase<?> openDatabase(final String iDbUrl, final OToken iToken) {
    final String path = getStoragePath(iDbUrl);
    final ODatabaseInternal<?> database = new ODatabaseDocumentTx(path);
    if (database.isClosed()) {
        final OStorage storage = database.getStorage();
        if (storage instanceof ODirectMemoryStorage && !storage.exists())
            database.create();
        else
            database.open(iToken);
    }
    return database;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODirectMemoryStorage(com.orientechnologies.orient.core.storage.impl.memory.ODirectMemoryStorage)

Example 27 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OObjectEntitySerializer method getCurrentSerializedSchema.

protected static OObjectEntitySerializedSchema getCurrentSerializedSchema() {
    OStorage storage = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage();
    OObjectEntitySerializedSchema serializedShchema = storage.getResource(SIMPLE_NAME, new Callable<OObjectEntitySerializedSchema>() {

        @Override
        public OObjectEntitySerializedSchema call() throws Exception {
            return new OObjectEntitySerializedSchema();
        }
    });
    return serializedShchema;
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OException(com.orientechnologies.common.exception.OException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OTransactionException(com.orientechnologies.orient.core.exception.OTransactionException) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException)

Example 28 with OStorage

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());
}
Also used : ODistributedStorage(com.orientechnologies.orient.server.distributed.impl.ODistributedStorage) ODistributedException(com.orientechnologies.orient.server.distributed.ODistributedException) OStorage(com.orientechnologies.orient.core.storage.OStorage) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 29 with OStorage

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;
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) AtomicReference(java.util.concurrent.atomic.AtomicReference) ODistributedDatabaseDeltaSyncException(com.orientechnologies.orient.server.distributed.task.ODistributedDatabaseDeltaSyncException) ODistributedDatabaseDeltaSyncException(com.orientechnologies.orient.server.distributed.task.ODistributedDatabaseDeltaSyncException) AtomicLong(java.util.concurrent.atomic.AtomicLong) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) AtomicLong(java.util.concurrent.atomic.AtomicLong) ODistributedDatabaseChunk(com.orientechnologies.orient.server.distributed.impl.ODistributedDatabaseChunk) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener)

Example 30 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class ServerRun method closeStorages.

public void closeStorages() {
    for (OStorage s : Orient.instance().getStorages()) {
        if (s instanceof OLocalPaginatedStorage && new File(((OLocalPaginatedStorage) s).getStoragePath()).getAbsolutePath().startsWith(getDatabasePath(""))) {
            try {
                s.close(true, false);
                Orient.instance().unregisterStorage(s);
            } catch (Exception e) {
            // IGNORE IT
            }
        }
    }
}
Also used : OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) OStorage(com.orientechnologies.orient.core.storage.OStorage) File(java.io.File) IOException(java.io.IOException)

Aggregations

OStorage (com.orientechnologies.orient.core.storage.OStorage)90 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)31 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)23 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)22 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)21 ORecordId (com.orientechnologies.orient.core.id.ORecordId)20 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)18 OPhysicalPosition (com.orientechnologies.orient.core.storage.OPhysicalPosition)12 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)11 File (java.io.File)11 ORID (com.orientechnologies.orient.core.id.ORID)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)7 Test (org.testng.annotations.Test)7 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)6 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)5 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5