Search in sources :

Example 66 with StoreDefinitionsMapper

use of voldemort.xml.StoreDefinitionsMapper in project voldemort by voldemort.

the class NonZonedRebalanceBatchPlanTest method setUp.

@Before
public void setUp() {
    try {
        storeDefList = new StoreDefinitionsMapper().readStoreList(new FileReader(new File(storeDefFile)));
        storeDefList2 = new StoreDefinitionsMapper().readStoreList(new StringReader(VoldemortTestConstants.getSingleStore322Xml()));
        test211StoreDef = Lists.newArrayList(ServerTestUtils.getStoreDef("test", 2, 1, 1, 1, 1, RoutingStrategyType.CONSISTENT_STRATEGY));
    } catch (FileNotFoundException e) {
        throw new RuntimeException("Failed to find storeDefFile:" + storeDefFile, e);
    }
}
Also used : StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) File(java.io.File) Before(org.junit.Before)

Example 67 with StoreDefinitionsMapper

use of voldemort.xml.StoreDefinitionsMapper in project voldemort by voldemort.

the class RebalanceRebootstrapConsistencyTest method setUp.

@Before
public void setUp() throws Exception {
    SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
    int numServers = 2;
    rwStoreDefWithReplication = new StoreDefinitionBuilder().setName(testStoreNameRW).setType(BdbStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
    /*
         * Bug fix: The old code was trying to rename a store during rebalance !
         * God knows why Renaming it back to the original store name and
         * changing other preferences (required reads = 2)
         */
    rwStoreDefWithReplication2 = new StoreDefinitionBuilder().setName(testStoreNameRW).setType(BdbStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(2).setRequiredReads(2).setPreferredWrites(1).setRequiredWrites(1).build();
    List<StoreDefinition> storedefs = new ArrayList<StoreDefinition>();
    storedefs.add(rwStoreDefWithReplication);
    String storesXmlStr = new StoreDefinitionsMapper().writeStoreList(storedefs);
    // create a temp file
    File tempStoresXml = ServerTestUtils.createTempFile("tempfile", ".tmp");
    BufferedWriter bw = new BufferedWriter(new FileWriter(tempStoresXml));
    bw.write(storesXmlStr);
    bw.close();
    VoldemortServer[] voldemortServers = new VoldemortServer[numServers];
    int[][] partitionMap = { { 0, 1 }, {} };
    cluster = ServerTestUtils.startVoldemortCluster(numServers, voldemortServers, partitionMap, socketStoreFactory, false, null, tempStoresXml.getAbsolutePath(), new Properties());
    servers = Lists.newArrayList();
    for (int i = 0; i < numServers; ++i) {
        servers.add(voldemortServers[i]);
    }
    socketUrl = voldemortServers[0].getIdentityNode().getSocketUrl().toString();
    bootStrapUrls = new String[1];
    bootStrapUrls[0] = socketUrl;
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setBootstrapUrls(bootStrapUrls).setClientZoneId(this.CLIENT_ZONE_ID);
    SystemStoreClientFactory<String, String> systemStoreFactory = new SystemStoreClientFactory<String, String>(clientConfig);
    sysVersionStore = systemStoreFactory.createSystemStore(SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name());
    repository = new SystemStoreRepository(clientConfig);
    repository.addSystemStore(sysVersionStore, SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name());
    this.scheduler = new SchedulerService(2, SystemTime.INSTANCE, true);
    Callable<Void> rebootstrapCallback = new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            // callbackForClusterChange();
            checkConsistentMetadata();
            return null;
        }
    };
    // Starting the Version Metadata Manager
    this.asyncCheckMetadata = new AsyncMetadataVersionManager(this.repository, rebootstrapCallback, null);
    scheduler.schedule(asyncCheckMetadata.getClass().getName(), asyncCheckMetadata, new Date(), 500);
    while (maxRetries < 3 && !asyncCheckMetadata.isActive) {
        Thread.sleep(500);
        maxRetries++;
    }
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) SystemStoreClientFactory(voldemort.client.SystemStoreClientFactory) FileWriter(java.io.FileWriter) SystemStoreRepository(voldemort.client.SystemStoreRepository) ArrayList(java.util.ArrayList) AsyncMetadataVersionManager(voldemort.client.scheduler.AsyncMetadataVersionManager) VoldemortServer(voldemort.server.VoldemortServer) Properties(java.util.Properties) Callable(java.util.concurrent.Callable) BufferedWriter(java.io.BufferedWriter) StoreDefinition(voldemort.store.StoreDefinition) ClientConfig(voldemort.client.ClientConfig) StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) Date(java.util.Date) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) File(java.io.File) SerializerDefinition(voldemort.serialization.SerializerDefinition) Before(org.junit.Before)

Example 68 with StoreDefinitionsMapper

use of voldemort.xml.StoreDefinitionsMapper in project voldemort by voldemort.

the class DataCleanupJobTest method runRetentionEnforcingStoreTest.

private void runRetentionEnforcingStoreTest(boolean onlineDeletes) throws InterruptedException {
    time.setTime(System.currentTimeMillis());
    StoreDefinition retentionStoreDef = new StoreDefinitionsMapper().readStoreList(new StringReader(VoldemortTestConstants.getStoreDefinitionsWithRetentionXml())).get(0);
    RetentionEnforcingStore store = new RetentionEnforcingStore(engine, retentionStoreDef, onlineDeletes, time);
    // do a bunch of puts
    store.put(new ByteArray("k1".getBytes()), new Versioned<byte[]>("v1".getBytes()), null);
    store.put(new ByteArray("k2".getBytes()), new Versioned<byte[]>("v2".getBytes()), null);
    long writeMs = System.currentTimeMillis();
    // wait for a bit and then do more puts
    Thread.sleep(2000);
    store.put(new ByteArray("k3".getBytes()), new Versioned<byte[]>("v3".getBytes()), null);
    store.put(new ByteArray("k4".getBytes()), new Versioned<byte[]>("v4".getBytes()), null);
    // move time forward just enough such that some keys will have expired.
    time.setTime(writeMs + retentionStoreDef.getRetentionDays() * Time.MS_PER_DAY + 1);
    assertEquals("k1 should have expired", 0, store.get(new ByteArray("k1".getBytes()), null).size());
    assertEquals("k2 should have expired", 0, store.get(new ByteArray("k2".getBytes()), null).size());
    assertTrue("k3 should not have expired", store.get(new ByteArray("k3".getBytes()), null).size() > 0);
    assertTrue("k4 should not have expired", store.get(new ByteArray("k4".getBytes()), null).size() > 0);
    // get all with k1, k4 should return a map with k4 alone
    Map<ByteArray, List<Versioned<byte[]>>> getAllResult = store.getAll(Arrays.asList(new ByteArray("k1".getBytes()), new ByteArray("k4".getBytes())), null);
    assertEquals("map should contain one element only", 1, getAllResult.size());
    assertEquals("k1 should not be present", false, getAllResult.containsKey(new ByteArray("k1".getBytes())));
    assertEquals("k4 should be present", true, getAllResult.containsKey(new ByteArray("k4".getBytes())));
    // if online deletes are not configured, we should see the deleted keys
    // in the base bdb store, so the datacleanup job can go and delete them
    assertEquals("k1 should be present", !onlineDeletes, engine.get(new ByteArray("k1".getBytes()), null).size() > 0);
    assertEquals("k2 should be present", !onlineDeletes, engine.get(new ByteArray("k2".getBytes()), null).size() > 0);
    // delete everything for next run
    engine.truncate();
}
Also used : RetentionEnforcingStore(voldemort.store.retention.RetentionEnforcingStore) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader) ByteArray(voldemort.utils.ByteArray) List(java.util.List)

Example 69 with StoreDefinitionsMapper

use of voldemort.xml.StoreDefinitionsMapper in project voldemort by voldemort.

the class ReplaceNodeCLI method getStoresXML.

private String getStoresXML() {
    StoreDefinitionsMapper storeMapper = new StoreDefinitionsMapper();
    Map<Integer, String> storeXMLInNodes = getMetadataXML(MetadataStore.STORES_KEY);
    List<StoreDefinition> storeList = null;
    String storeXML = null;
    for (Map.Entry<Integer, String> storeNodeId : storeXMLInNodes.entrySet()) {
        String xml = storeNodeId.getValue();
        List<StoreDefinition> storeDefinitions = storeMapper.readStoreList(new StringReader(xml), false);
        if (storeList == null) {
            storeList = storeDefinitions;
            storeXML = xml;
        } else if (storeList.equals(storeDefinitions) == false) {
            throw new VoldemortApplicationException("Store XMLs are different across nodes, fix that before the node swap...aborting " + storeNodeId.getKey());
        }
    }
    return storeXML;
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map)

Example 70 with StoreDefinitionsMapper

use of voldemort.xml.StoreDefinitionsMapper in project voldemort by voldemort.

the class ZoneShrinkageCLI method shrinkStoresXml.

protected static String shrinkStoresXml(String storesXml, int droppingZoneId) {
    List<StoreDefinition> initialStoreDefs = new StoreDefinitionsMapper().readStoreList(new StringReader(storesXml));
    List<StoreDefinition> finalStoreDefs = RebalanceUtils.dropZone(initialStoreDefs, droppingZoneId);
    String newStoresXml = new StoreDefinitionsMapper().writeStoreList(finalStoreDefs);
    return newStoresXml;
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader)

Aggregations

StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)82 StoreDefinition (voldemort.store.StoreDefinition)50 File (java.io.File)44 StringReader (java.io.StringReader)29 ClusterMapper (voldemort.xml.ClusterMapper)26 Before (org.junit.Before)19 Cluster (voldemort.cluster.Cluster)18 Properties (java.util.Properties)16 VoldemortException (voldemort.VoldemortException)15 Test (org.junit.Test)14 Node (voldemort.cluster.Node)14 AdminClient (voldemort.client.protocol.admin.AdminClient)13 ArrayList (java.util.ArrayList)12 StoreDefinitionBuilder (voldemort.store.StoreDefinitionBuilder)12 IOException (java.io.IOException)10 OptionSet (joptsimple.OptionSet)9 VoldemortServer (voldemort.server.VoldemortServer)9 ByteArray (voldemort.utils.ByteArray)9 HashMap (java.util.HashMap)8 SerializerDefinition (voldemort.serialization.SerializerDefinition)8