Search in sources :

Example 51 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class KCVSConfiguration method set.

public <O> void set(String key, O value, O expectedValue, final boolean checkExpectedValue) {
    final StaticBuffer column = string2StaticBuffer(key);
    final List<Entry> additions;
    final List<StaticBuffer> deletions;
    if (value != null) {
        // Addition
        additions = new ArrayList<>(1);
        deletions = KeyColumnValueStore.NO_DELETIONS;
        StaticBuffer val = object2StaticBuffer(value);
        additions.add(StaticArrayEntry.of(column, val));
    } else {
        // Deletion
        additions = KeyColumnValueStore.NO_ADDITIONS;
        deletions = new ArrayList<>(1);
        deletions.add(column);
    }
    final StaticBuffer expectedValueBuffer;
    if (checkExpectedValue && expectedValue != null) {
        expectedValueBuffer = object2StaticBuffer(expectedValue);
    } else {
        expectedValueBuffer = null;
    }
    BackendOperation.execute(new BackendOperation.Transactional<Boolean>() {

        @Override
        public Boolean call(StoreTransaction txh) throws BackendException {
            if (checkExpectedValue)
                store.acquireLock(rowKey, column, expectedValueBuffer, txh);
            store.mutate(rowKey, additions, deletions, txh);
            return true;
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException)

Example 52 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class CQLStoreTest method testGetKeysWithoutUnorderedScan.

@Test
@FeatureFlag(feature = JanusGraphFeature.OrderedScan)
public void testGetKeysWithoutUnorderedScan() throws BackendException, NoSuchFieldException, IllegalAccessException {
    // support ordered scan but not unordered scan
    Field field = StandardStoreFeatures.class.getDeclaredField("unorderedScan");
    field.setAccessible(true);
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    field.set(manager.getFeatures(), false);
    Exception ex = assertThrows(PermanentBackendException.class, () -> store.getKeys(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(4)), tx));
    assertEquals("This operation is only allowed when partitioner supports unordered scan", ex.getMessage());
    assertDoesNotThrow(() -> store.getKeys(new KeyRangeQuery(BufferUtil.getLongBuffer(1), BufferUtil.getLongBuffer(1000), BufferUtil.getLongBuffer(1), BufferUtil.getLongBuffer(1000)), tx));
}
Also used : Field(java.lang.reflect.Field) KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeyColumnValueStoreTest(org.janusgraph.diskstorage.KeyColumnValueStoreTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 53 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class IDPoolTest method testAllocationTimeoutAndRecovery.

@Test
public void testAllocationTimeoutAndRecovery() throws BackendException {
    IMocksControl ctrl = EasyMock.createStrictControl();
    final int partition = 42;
    final int idNamespace = 777;
    final Duration timeout = Duration.ofSeconds(1L);
    final IDAuthority mockAuthority = ctrl.createMock(IDAuthority.class);
    // Sleep for two seconds, then throw a BackendException
    // this whole delegate could be deleted if we abstracted StandardIDPool's internal executor and stopwatches
    expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andDelegateTo(new IDAuthority() {

        @Override
        public IDBlock getIDBlock(int partition, int idNamespace, Duration timeout) throws BackendException {
            assertThrows(InterruptedException.class, () -> Thread.sleep(2000L));
            throw new TemporaryBackendException("slow backend");
        }

        @Override
        public List<KeyRange> getLocalIDPartition() {
            throw new IllegalArgumentException();
        }

        @Override
        public void setIDBlockSizer(IDBlockSizer sizer) {
            throw new IllegalArgumentException();
        }

        @Override
        public void close() {
            throw new IllegalArgumentException();
        }

        @Override
        public String getUniqueID() {
            throw new IllegalArgumentException();
        }

        @Override
        public boolean supportsInterruption() {
            return true;
        }
    });
    expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andReturn(new IDBlock() {

        @Override
        public long numIds() {
            return 2;
        }

        @Override
        public long getId(long index) {
            return 200;
        }
    });
    expect(mockAuthority.supportsInterruption()).andStubReturn(true);
    ctrl.replay();
    StandardIDPool pool = new StandardIDPool(mockAuthority, partition, idNamespace, Integer.MAX_VALUE, timeout, 0.1);
    assertThrows(JanusGraphException.class, pool::nextID);
    long nextID = pool.nextID();
    assertEquals(200, nextID);
    ctrl.verify();
}
Also used : IDBlockSizer(org.janusgraph.graphdb.database.idassigner.IDBlockSizer) Duration(java.time.Duration) BackendException(org.janusgraph.diskstorage.BackendException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IMocksControl(org.easymock.IMocksControl) StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IDAuthority(org.janusgraph.diskstorage.IDAuthority) IDBlock(org.janusgraph.diskstorage.IDBlock) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 54 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class StandardLogProcessorFrameworkTest method testAddLogProcessor.

@Test
public void testAddLogProcessor() throws BackendException, NoSuchFieldException, IllegalAccessException {
    StandardJanusGraph graph = createGraphWithMockedInternals();
    StandardLogProcessorFramework logProcessorFramework = new StandardLogProcessorFramework(graph);
    logProcessorFramework.addLogProcessor("foo-identifier").addProcessor((tx, txId, changeState) -> {
    // no-op processor
    }).setStartTimeNow().setProcessorIdentifier("bar-processor").build();
    Field processorLogsField = logProcessorFramework.getClass().getDeclaredField("processorLogs");
    processorLogsField.setAccessible(true);
    Map<String, Log> processorLogs = (Map<String, Log>) processorLogsField.get(logProcessorFramework);
    assertNotNull(processorLogs, "processorLogs must not be null or empty after adding a log processor");
    assertFalse(processorLogs.isEmpty(), "processorLogs should be non-empty after adding a processor");
}
Also used : BackendException(org.janusgraph.diskstorage.BackendException) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) Log(org.janusgraph.diskstorage.log.Log) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) Backend(org.janusgraph.diskstorage.Backend) Test(org.junit.jupiter.api.Test) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) Map(java.util.Map) ReadMarker(org.janusgraph.diskstorage.log.ReadMarker) LinkedList(java.util.LinkedList) Mockito.anyString(org.mockito.Mockito.anyString) Mockito.mock(org.mockito.Mockito.mock) Field(java.lang.reflect.Field) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) Log(org.janusgraph.diskstorage.log.Log) Mockito.anyString(org.mockito.Mockito.anyString) Map(java.util.Map) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 55 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class KCVSLog method readSetting.

private long readSetting(String identifier, final StaticBuffer column, long defaultValue) {
    final StaticBuffer key = getSettingKey(identifier);
    StaticBuffer value = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() {

        @Override
        public StaticBuffer call(StoreTransaction txh) throws BackendException {
            return KCVSUtil.get(store, key, column, txh);
        }

        @Override
        public String toString() {
            return "readingLogSetting";
        }
    }, this, times, maxReadTime);
    if (value == null)
        return defaultValue;
    else {
        Preconditions.checkArgument(value.length() == 8);
        return value.getLong(0);
    }
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Aggregations

BackendException (org.janusgraph.diskstorage.BackendException)62 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)26 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)18 JanusGraphException (org.janusgraph.core.JanusGraphException)17 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)16 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)16 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Map (java.util.Map)12 Duration (java.time.Duration)11 HashMap (java.util.HashMap)11 Configuration (org.janusgraph.diskstorage.configuration.Configuration)11 Entry (org.janusgraph.diskstorage.Entry)10 Test (org.junit.jupiter.api.Test)10 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)9 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)9 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)9 IOException (java.io.IOException)8 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)8 Preconditions (com.google.common.base.Preconditions)6