Search in sources :

Example 91 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class RepairJobTest method testRepairJob.

@Test
public void testRepairJob() {
    // start the servers
    setUp();
    // Create socket store
    storeMap = createSocketStore(storeDefs.get(0));
    // Generate random data, populate cluster with it.
    HashMap<String, String> testEntries = ServerTestUtils.createRandomKeyValueString(128);
    populateData(testEntries);
    // create admin client and run repair on all nodes
    AdminClient admin = new AdminClient(cluster);
    for (int i = 0; i < 9; i++) {
        admin.storeMntOps.repairJob(i);
    }
    // wait for the repair to complete
    for (int i = 0; i < 9; i++) {
        ServerTestUtils.waitForAsyncOperationOnServer(serverMap.get(i), "Repair", 5000);
    }
    BaseStoreRoutingPlan storeInstance = new BaseStoreRoutingPlan(cluster, storeDefs.get(0));
    for (Entry<String, String> entry : testEntries.entrySet()) {
        ByteArray keyBytes = new ByteArray(ByteUtils.getBytes(entry.getKey(), "UTF-8"));
        List<Integer> preferenceNodes = storeInstance.getReplicationNodeList(keyBytes.get());
        List<Integer> allNodes = new ArrayList<Integer>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8));
        // Repair job should have deleted the keys on the nodes that
        // shouldn't have been
        // hosting the key. Go over all these remaining nodes to make sure
        // that it's true.
        allNodes.removeAll(preferenceNodes);
        for (int nodeId : allNodes) {
            try {
                List<Versioned<byte[]>> retVal = storeMap.get(nodeId).get(keyBytes, null);
                assertEquals("Repair did not run properly as it left the key it should have" + " deleted", retVal.isEmpty(), true);
            } catch (Exception e) {
            // We expect a bunch of invalidmetadata exceptions as we are
            // asking for key
            // that doesn't belong to the nodes. Hence leaving the catch
            // empty.
            }
        }
        // pref list.
        for (int nodeId : preferenceNodes) {
            try {
                List<Versioned<byte[]>> retVal = storeMap.get(nodeId).get(keyBytes, null);
                assertEquals("Repair job has deleted keys that it should not have", retVal.isEmpty(), false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    for (Store<ByteArray, byte[], byte[]> store : storeMap.values()) {
        store.close();
    }
}
Also used : Versioned(voldemort.versioning.Versioned) ArrayList(java.util.ArrayList) ByteArray(voldemort.utils.ByteArray) BaseStoreRoutingPlan(voldemort.routing.BaseStoreRoutingPlan) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 92 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class StorageServiceTest method testMetadataVersionsInit.

@Test
public void testMetadataVersionsInit() {
    Store<ByteArray, byte[], byte[]> versionStore = storeRepository.getLocalStore(SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name());
    Properties props = new Properties();
    try {
        ByteArray metadataVersionsKey = new ByteArray(SystemStoreConstants.VERSIONS_METADATA_KEY.getBytes());
        List<Versioned<byte[]>> versionList = versionStore.get(metadataVersionsKey, null);
        if (versionList != null && versionList.size() > 0) {
            byte[] versionsByteArray = versionList.get(0).getValue();
            if (versionsByteArray != null) {
                props.load(new ByteArrayInputStream(versionsByteArray));
            } else {
                fail("Illegal value returned for metadata key: " + SystemStoreConstants.VERSIONS_METADATA_KEY);
            }
        } else {
            fail("Illegal value returned for metadata key: " + SystemStoreConstants.VERSIONS_METADATA_KEY);
        }
        // Check if version exists for cluster.xml
        if (!props.containsKey(SystemStoreConstants.CLUSTER_VERSION_KEY)) {
            fail(SystemStoreConstants.CLUSTER_VERSION_KEY + " not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
        }
        // Check if version exists for stores.xml
        if (!props.containsKey(SystemStoreConstants.STORES_VERSION_KEY)) {
            fail(SystemStoreConstants.STORES_VERSION_KEY + " not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
        }
        // Check if version exists for each store
        for (StoreDefinition def : storeDefs) {
            if (!props.containsKey(def.getName())) {
                fail(def.getName() + " store not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
            }
        }
    } catch (Exception e) {
        fail("Error in retrieving : " + SystemStoreConstants.VERSIONS_METADATA_KEY + " key from " + SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name() + " store. ");
    }
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArrayInputStream(java.io.ByteArrayInputStream) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray) Properties(java.util.Properties) IOException(java.io.IOException) Test(org.junit.Test)

Example 93 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class FileBackedCachingStorageEngineTest method getKeys.

/*
     * Calling getStrings to make it readable (easier debugging)
     */
@Override
public List<ByteArray> getKeys(int numKeys) {
    List<String> keyList = getStrings(numKeys, 10);
    List<ByteArray> byteArrayKeyList = new ArrayList<ByteArray>();
    for (String s : keyList) {
        byteArrayKeyList.add(new ByteArray(s.getBytes()));
    }
    return byteArrayKeyList;
}
Also used : ArrayList(java.util.ArrayList) ByteArray(voldemort.utils.ByteArray)

Example 94 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class FileBackedCachingStorageEngineTest method testGetAll.

@Override
@Test
public void testGetAll() throws Exception {
    Store<ByteArray, byte[], byte[]> store = getStore();
    int putCount = 10;
    List<ByteArray> keys = getKeys(putCount);
    List<byte[]> values = getValues(putCount);
    assertEquals(putCount, values.size());
    VectorClock clock = new VectorClock();
    for (int i = 0; i < putCount; i++) {
        store.put(keys.get(i), new Versioned<byte[]>(values.get(i), clock), null);
        clock = clock.incremented(0, System.currentTimeMillis());
    }
    int countForGet = putCount / 2;
    List<ByteArray> keysForGet = keys.subList(0, countForGet);
    List<byte[]> valuesForGet = values.subList(0, countForGet);
    Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keysForGet, null);
    assertGetAllValues(keysForGet, valuesForGet, result);
}
Also used : VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) ArrayList(java.util.ArrayList) List(java.util.List) AbstractStoreTest(voldemort.store.AbstractStoreTest) Test(org.junit.Test)

Example 95 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class FileBackedCachingStorageEngineTest method testDelete.

@Override
public void testDelete() {
    ByteArray key = getKey();
    Store<ByteArray, byte[], byte[]> store = getStore();
    VectorClock c1 = getClock(1, 1);
    byte[] value = getValue();
    // can't delete something that isn't there
    assertTrue(!store.delete(key, c1));
    store.put(key, new Versioned<byte[]>(value, c1), null);
    assertEquals(1, store.get(key, null).size());
    // now delete that version too
    assertTrue("Delete failed!", store.delete(key, c1));
    assertEquals(0, store.get(key, null).size());
}
Also used : VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray)

Aggregations

ByteArray (voldemort.utils.ByteArray)309 Versioned (voldemort.versioning.Versioned)130 Test (org.junit.Test)125 VoldemortException (voldemort.VoldemortException)67 VectorClock (voldemort.versioning.VectorClock)65 ArrayList (java.util.ArrayList)61 Node (voldemort.cluster.Node)61 List (java.util.List)58 HashMap (java.util.HashMap)53 StoreDefinition (voldemort.store.StoreDefinition)49 Cluster (voldemort.cluster.Cluster)33 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)31 Store (voldemort.store.Store)31 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)31 IOException (java.io.IOException)30 Slop (voldemort.store.slop.Slop)29 Map (java.util.Map)28 Pair (voldemort.utils.Pair)28 UnreachableStoreException (voldemort.store.UnreachableStoreException)26 StatTrackingStore (voldemort.store.stats.StatTrackingStore)25