Search in sources :

Example 1 with OOfflineClusterException

use of com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method executeReadRecord.

/**
   * This method is internal, it can be subject to signature change or be removed, do not use.
   *
   * @Internal
   */
public <RET extends ORecord> RET executeReadRecord(final ORecordId rid, ORecord iRecord, final int recordVersion, final String fetchPlan, final boolean ignoreCache, final boolean iUpdateCache, final boolean loadTombstones, final OStorage.LOCKING_STRATEGY lockingStrategy, RecordReader recordReader) {
    checkOpeness();
    checkIfActive();
    getMetadata().makeThreadLocalSchemaSnapshot();
    ORecordSerializationContext.pushContext();
    try {
        checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_READ, getClusterNameById(rid.getClusterId()));
        // SEARCH IN LOCAL TX
        ORecord record = getTransaction().getRecord(rid);
        if (record == OTransactionRealAbstract.DELETED_RECORD)
            // DELETED IN TX
            return null;
        if (record == null && !ignoreCache)
            // SEARCH INTO THE CACHE
            record = getLocalCache().findRecord(rid);
        if (record != null) {
            if (iRecord != null) {
                iRecord.fromStream(record.toStream());
                ORecordInternal.setVersion(iRecord, record.getVersion());
                record = iRecord;
            }
            OFetchHelper.checkFetchPlanValid(fetchPlan);
            if (callbackHooks(ORecordHook.TYPE.BEFORE_READ, record) == ORecordHook.RESULT.SKIP)
                return null;
            if (record.getInternalStatus() == ORecordElement.STATUS.NOT_LOADED)
                record.reload();
            if (lockingStrategy == OStorage.LOCKING_STRATEGY.KEEP_SHARED_LOCK) {
                OLogManager.instance().warn(this, "You use deprecated record locking strategy: %s it may lead to deadlocks " + lockingStrategy);
                record.lock(false);
            } else if (lockingStrategy == OStorage.LOCKING_STRATEGY.KEEP_EXCLUSIVE_LOCK) {
                OLogManager.instance().warn(this, "You use deprecated record locking strategy: %s it may lead to deadlocks " + lockingStrategy);
                record.lock(true);
            }
            callbackHooks(ORecordHook.TYPE.AFTER_READ, record);
            if (record instanceof ODocument)
                ODocumentInternal.checkClass((ODocument) record, this);
            return (RET) record;
        }
        final ORawBuffer recordBuffer;
        if (!rid.isValid())
            recordBuffer = null;
        else {
            OFetchHelper.checkFetchPlanValid(fetchPlan);
            int version;
            if (iRecord != null)
                version = iRecord.getVersion();
            else
                version = recordVersion;
            recordBuffer = recordReader.readRecord(storage, rid, fetchPlan, ignoreCache, version);
        }
        if (recordBuffer == null)
            return null;
        if (iRecord == null || ORecordInternal.getRecordType(iRecord) != recordBuffer.recordType)
            // NO SAME RECORD TYPE: CAN'T REUSE OLD ONE BUT CREATE A NEW ONE FOR IT
            iRecord = Orient.instance().getRecordFactoryManager().newInstance(recordBuffer.recordType);
        ORecordInternal.fill(iRecord, rid, recordBuffer.version, recordBuffer.buffer, false);
        if (iRecord instanceof ODocument)
            ODocumentInternal.checkClass((ODocument) iRecord, this);
        if (ORecordVersionHelper.isTombstone(iRecord.getVersion()))
            return (RET) iRecord;
        if (callbackHooks(ORecordHook.TYPE.BEFORE_READ, iRecord) == ORecordHook.RESULT.SKIP)
            return null;
        iRecord.fromStream(recordBuffer.buffer);
        callbackHooks(ORecordHook.TYPE.AFTER_READ, iRecord);
        if (iUpdateCache)
            getLocalCache().updateRecord(iRecord);
        return (RET) iRecord;
    } catch (OOfflineClusterException t) {
        throw t;
    } catch (ORecordNotFoundException t) {
        throw t;
    } catch (Throwable t) {
        if (rid.isTemporary())
            throw OException.wrapException(new ODatabaseException("Error on retrieving record using temporary RID: " + rid), t);
        else
            throw OException.wrapException(new ODatabaseException("Error on retrieving record " + rid + " (cluster: " + storage.getPhysicalClusterNameById(rid.getClusterId()) + ")"), t);
    } finally {
        ORecordSerializationContext.pullContext();
        getMetadata().clearThreadLocalSchemaSnapshot();
    }
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)

Example 2 with OOfflineClusterException

use of com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException in project orientdb by orientechnologies.

the class ONetworkProtocolBinary method updateRecord.

protected int updateRecord(OClientConnection connection, final ORecordId rid, final byte[] buffer, final int version, final byte recordType, boolean updateContent) {
    ODatabaseDocumentInternal database = connection.getDatabase();
    final ORecord newRecord = Orient.instance().getRecordFactoryManager().newInstance(recordType);
    fillRecord(connection, rid, buffer, version, newRecord);
    ORecordInternal.setContentChanged(newRecord, updateContent);
    ORecordInternal.getDirtyManager(newRecord).clearForSave();
    ORecord currentRecord = null;
    if (newRecord instanceof ODocument) {
        try {
            currentRecord = database.load(rid);
        } catch (ORecordNotFoundException e) {
            // MAINTAIN COHERENT THE BEHAVIOR FOR ALL THE STORAGE TYPES
            if (e.getCause() instanceof OOfflineClusterException)
                throw (OOfflineClusterException) e.getCause();
        }
        if (currentRecord == null)
            throw new ORecordNotFoundException(rid);
        ((ODocument) currentRecord).merge((ODocument) newRecord, false, false);
    } else
        currentRecord = newRecord;
    ORecordInternal.setVersion(currentRecord, version);
    database.save(currentRecord);
    if (currentRecord.getIdentity().toString().equals(database.getStorage().getConfiguration().indexMgrRecordId) && !database.getStatus().equals(ODatabase.STATUS.IMPORTING)) {
        // FORCE INDEX MANAGER UPDATE. THIS HAPPENS FOR DIRECT CHANGES FROM REMOTE LIKE IN GRAPH
        database.getMetadata().getIndexManager().reload();
    }
    return currentRecord.getVersion();
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)

Example 3 with OOfflineClusterException

use of com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException in project orientdb by orientechnologies.

the class ONetworkProtocolBinary method deleteRecord.

protected int deleteRecord(final ODatabaseDocument iDatabase, final ORID rid, final int version) {
    try {
        // TRY TO SEE IF THE RECORD EXISTS
        final ORecord record = rid.getRecord();
        if (record == null)
            return 0;
        iDatabase.delete(rid, version);
        return 1;
    } catch (ORecordNotFoundException e) {
        // MAINTAIN COHERENT THE BEHAVIOR FOR ALL THE STORAGE TYPES
        if (e.getCause() instanceof OOfflineClusterException)
            throw (OOfflineClusterException) e.getCause();
    } catch (OOfflineClusterException e) {
        throw e;
    } catch (Exception e) {
    // IGNORE IT
    }
    return 0;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OLockException(com.orientechnologies.common.concur.lock.OLockException) OException(com.orientechnologies.common.exception.OException) SocketException(java.net.SocketException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OIOException(com.orientechnologies.common.io.OIOException) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException) IOException(java.io.IOException) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)

Example 4 with OOfflineClusterException

use of com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException in project orientdb by orientechnologies.

the class ONetworkProtocolBinary method commit.

protected void commit(OClientConnection connection) throws IOException {
    setDataCommandInfo(connection, "Transaction commit");
    if (!isConnectionAlive(connection))
        return;
    final OTransactionOptimisticProxy tx = new OTransactionOptimisticProxy(connection, this);
    try {
        try {
            connection.getDatabase().begin(tx);
        } catch (final ORecordNotFoundException e) {
            sendShutdown();
            throw e.getCause() instanceof OOfflineClusterException ? (OOfflineClusterException) e.getCause() : e;
        }
        try {
            try {
                connection.getDatabase().commit();
            } catch (final ORecordNotFoundException e) {
                throw e.getCause() instanceof OOfflineClusterException ? (OOfflineClusterException) e.getCause() : e;
            }
            beginResponse();
            try {
                sendOk(connection, clientTxId);
                // SEND BACK ALL THE RECORD IDS FOR THE CREATED RECORDS
                channel.writeInt(tx.getCreatedRecords().size());
                for (Entry<ORecordId, ORecord> entry : tx.getCreatedRecords().entrySet()) {
                    channel.writeRID(entry.getKey());
                    channel.writeRID(entry.getValue().getIdentity());
                    // IF THE NEW OBJECT HAS VERSION > 0 MEANS THAT HAS BEEN UPDATED IN THE SAME TX. THIS HAPPENS FOR GRAPHS
                    if (entry.getValue().getVersion() > 0)
                        tx.getUpdatedRecords().put((ORecordId) entry.getValue().getIdentity(), entry.getValue());
                }
                // SEND BACK ALL THE NEW VERSIONS FOR THE UPDATED RECORDS
                channel.writeInt(tx.getUpdatedRecords().size());
                for (Entry<ORecordId, ORecord> entry : tx.getUpdatedRecords().entrySet()) {
                    channel.writeRID(entry.getKey());
                    channel.writeVersion(entry.getValue().getVersion());
                }
                if (connection.getData().protocolVersion >= 20)
                    sendCollectionChanges(connection);
            } finally {
                endResponse(connection);
            }
        } catch (Exception e) {
            if (connection != null && connection.getDatabase() != null) {
                if (connection.getDatabase().getTransaction().isActive())
                    connection.getDatabase().rollback(true);
                final OSBTreeCollectionManager collectionManager = connection.getDatabase().getSbTreeCollectionManager();
                if (collectionManager != null)
                    collectionManager.clearChangedIds();
            }
            sendErrorOrDropConnection(connection, clientTxId, e);
        }
    } catch (OTransactionAbortedException e) {
    // TX ABORTED BY THE CLIENT
    } catch (Exception e) {
        // Error during TX initialization, possibly index constraints violation.
        if (tx.isActive())
            tx.rollback(true, -1);
        sendErrorOrDropConnection(connection, clientTxId, e);
    }
}
Also used : OTransactionOptimisticProxy(com.orientechnologies.orient.server.tx.OTransactionOptimisticProxy) ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OLockException(com.orientechnologies.common.concur.lock.OLockException) OException(com.orientechnologies.common.exception.OException) SocketException(java.net.SocketException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OIOException(com.orientechnologies.common.io.OIOException) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException) IOException(java.io.IOException) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException) OSBTreeCollectionManager(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)

Example 5 with OOfflineClusterException

use of com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException in project orientdb by orientechnologies.

the class SchemaTest method testOfflineCluster.

public void testOfflineCluster() {
    database.command(new OCommandSQL("create class TestOffline")).execute();
    database.command(new OCommandSQL("insert into TestOffline set status = 'offline'")).execute();
    List<OIdentifiable> result = database.command(new OCommandSQL("select from TestOffline")).execute();
    Assert.assertNotNull(result);
    Assert.assertFalse(result.isEmpty());
    ODocument record = result.get(0).getRecord();
    // TEST NO EFFECTS
    Boolean changed = database.command(new OCommandSQL("alter cluster TestOffline status online")).execute();
    Assert.assertFalse(changed);
    // PUT IT OFFLINE
    changed = database.command(new OCommandSQL("alter cluster TestOffline* status offline")).execute();
    Assert.assertTrue(changed);
    // NO DATA?
    result = database.command(new OCommandSQL("select from TestOffline")).execute();
    Assert.assertNotNull(result);
    Assert.assertTrue(result.isEmpty());
    // TEST NO EFFECTS
    changed = database.command(new OCommandSQL("alter cluster TestOffline* status offline")).execute();
    Assert.assertFalse(changed);
    // TEST SAVING OF OFFLINE STATUS
    // TEST UPDATE - NO EFFECT
    Assert.assertEquals(database.command(new OCommandSQL("update TestOffline set name = 'yeah'")).execute(), 0);
    // TEST DELETE - NO EFFECT
    Assert.assertEquals(database.command(new OCommandSQL("delete from TestOffline")).execute(), 0);
    // TEST CREATE -> EXCEPTION
    try {
        Object res = database.command(new OCommandSQL("insert into TestOffline set name = 'offline', password = 'offline', status = 'ACTIVE'")).execute();
        Assert.assertTrue(false);
    } catch (OException e) {
        Throwable cause = e;
        while (cause.getCause() != null) cause = cause.getCause();
        Assert.assertTrue(cause instanceof OOfflineClusterException);
    }
    // TEST UPDATE RECORD -> EXCEPTION
    try {
        record.field("status", "offline").save();
        Assert.assertTrue(false);
    } catch (OException e) {
        Throwable cause = e;
        while (cause.getCause() != null) cause = cause.getCause();
        Assert.assertTrue(cause instanceof OOfflineClusterException);
    }
    // TEST DELETE RECORD -> EXCEPTION
    try {
        record.delete();
        Assert.assertTrue(false);
    } catch (OOfflineClusterException e) {
        Assert.assertTrue(true);
    }
    // TEST DELETE RECORD -> EXCEPTION
    try {
        record.reload(null, true);
        Assert.assertTrue(false);
    } catch (ORecordNotFoundException e) {
        Assert.assertTrue(e.getCause() instanceof OOfflineClusterException);
    }
    // RESTORE IT ONLINE
    changed = database.command(new OCommandSQL("alter cluster TestOffline status online")).execute();
    Assert.assertTrue(changed);
    result = database.command(new OCommandSQL("select from TestOffline")).execute();
    Assert.assertNotNull(result);
    Assert.assertFalse(result.isEmpty());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)

Aggregations

OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)5 ORecord (com.orientechnologies.orient.core.record.ORecord)4 OException (com.orientechnologies.common.exception.OException)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 IOException (java.io.IOException)3 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)2 OLockException (com.orientechnologies.common.concur.lock.OLockException)2 OIOException (com.orientechnologies.common.io.OIOException)2 SocketException (java.net.SocketException)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OSBTreeCollectionManager (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OTransactionOptimisticProxy (com.orientechnologies.orient.server.tx.OTransactionOptimisticProxy)1