Search in sources :

Example 6 with SchedulerService

use of voldemort.common.service.SchedulerService 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 7 with SchedulerService

use of voldemort.common.service.SchedulerService in project voldemort by voldemort.

the class DataCleanupJobTest method testCleanupFrequency.

@Test
public void testCleanupFrequency() throws InterruptedException {
    SchedulerService scheduler = new SchedulerService(1, time);
    String cleanUpJobName = "cleanup-freq-test";
    try {
        MockTime mockTime = new MockTime(System.currentTimeMillis());
        // clean up will purge everything older than last 2 seconds
        DataCleanupJob cleanupJob = new DataCleanupJob<ByteArray, byte[], byte[]>(engine, new ScanPermitWrapper(1), STORE_NAME, mockTime, metadataStore);
        // and will run every 3 seconds starting now
        scheduler.schedule(cleanUpJobName, cleanupJob, new Date(), 1 * Time.MS_PER_SECOND);
        // load some data
        putWithTimeStamp(0, 10, System.currentTimeMillis());
        Thread.sleep(3 * Time.MS_PER_SECOND);
        // None of the keys should have been deleted
        assertPresence(0, 10);
        assertEquals("No entries must be deleted now", 0, cleanupJob.getEntriesDeleted());
        assertTrue("Entries are scanned, but not deleted", cleanupJob.getEntriesScanned() > 0);
        // Increase the mockTime by a day and a millisecond.
        mockTime.setTime(System.currentTimeMillis() + START_RETENTION * Time.MS_PER_DAY + 1);
        // load some more data
        putWithTimeStamp(10, 20, mockTime.getMilliseconds());
        // give time for data cleanup to run
        Thread.sleep(3 * Time.MS_PER_SECOND);
        // first batch of writes should have been deleted
        assertAbsence(0, 10);
        // and later ones retained.
        assertPresence(10, 20);
        assertEquals("10 entries should be deleted", 10, cleanupJob.getEntriesDeleted());
        // Insert 10 keys that are separated by a day and millisecond
        long currentTime = mockTime.getMilliseconds();
        for (int i = 20; i < 30; i++) {
            currentTime += Time.MS_PER_DAY + 1;
            putWithTimeStamp(i, i + 1, currentTime);
        }
        mockTime.setTime(currentTime);
        updateStoreDef(REDUCED_RETENTION);
        Thread.sleep(3 * Time.MS_PER_SECOND);
        assertAbsence(10, 28);
        assertEquals("28 entries should be deleted", 28, cleanupJob.getEntriesDeleted());
        // Only last 2 keys should be present, third key is old by 2 days
        // and 2 milliseconds
        assertPresence(28, 30);
    } finally {
        scheduler.terminate(cleanUpJobName);
        scheduler.stop();
    }
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) ScanPermitWrapper(voldemort.server.storage.ScanPermitWrapper) DataCleanupJob(voldemort.server.scheduler.DataCleanupJob) MockTime(voldemort.MockTime) Date(java.util.Date) Test(org.junit.Test)

Example 8 with SchedulerService

use of voldemort.common.service.SchedulerService in project voldemort by voldemort.

the class AbstractStoreClientFactory method initZenStoreResourcesIfNeeded.

private synchronized void initZenStoreResourcesIfNeeded() {
    // concurrently.
    if (!isZenStoreResourcesInited.get()) {
        // since the method is synchronized, only one winning thread will
        // make it here.
        this.sysRepository = new SystemStoreRepository(config);
        // Start up the scheduler
        this.scheduler = new SchedulerService(config.getAsyncJobThreadPoolSize(), SystemTime.INSTANCE, true);
        this.scheduler.start();
        isZenStoreResourcesInited.set(true);
    }
}
Also used : SchedulerService(voldemort.common.service.SchedulerService)

Example 9 with SchedulerService

use of voldemort.common.service.SchedulerService in project voldemort by voldemort.

the class RepairJobTest method setUp.

public void setUp() {
    File temp = TestUtils.createTempDir();
    VoldemortConfig config = new VoldemortConfig(0, temp.getAbsolutePath());
    new File(config.getMetadataDirectory()).mkdir();
    this.serverMap = new HashMap<Integer, VoldemortServer>();
    this.scheduler = new SchedulerService(1, new MockTime());
    this.cluster = VoldemortTestConstants.getNineNodeCluster();
    StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
    this.storeDefs = mapper.readStoreList(new StringReader((VoldemortTestConstants.getSingleStore322Xml())));
    this.storeRepository = new StoreRepository();
    this.metadataStore = ServerTestUtils.createMetadataStore(cluster, storeDefs);
    storage = new StorageService(storeRepository, metadataStore, scheduler, config);
    // Start the storage service
    storage.start();
    this.socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
    String storeDefsString = mapper.writeStoreList(storeDefs);
    File file = null;
    try {
        file = ServerTestUtils.createTempFile("single-store-", ".xml");
        FileUtils.writeStringToFile(file, storeDefsString);
        String storeDefFile = file.getAbsolutePath();
        List<Integer> nodesToStart = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8);
        // Start the servers
        startServers(cluster, storeDefFile, nodesToStart, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StoreRepository(voldemort.server.StoreRepository) VoldemortServer(voldemort.server.VoldemortServer) VoldemortConfig(voldemort.server.VoldemortConfig) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) StringReader(java.io.StringReader) File(java.io.File) MockTime(voldemort.MockTime)

Example 10 with SchedulerService

use of voldemort.common.service.SchedulerService in project voldemort by voldemort.

the class StorageServiceTest method setUp.

@Override
@Before
public void setUp() {
    // this is turned off by default
    config.setEnableServerRouting(true);
    metadataDir = new File(config.getMetadataDirectory());
    metadataDir.mkdir();
    config.setBdbCacheSize(100000);
    this.scheduler = new SchedulerService(1, new MockTime());
    this.storeRepository = new StoreRepository();
    storage = new StorageService(storeRepository, mdStore, scheduler, config);
    storage.start();
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) StoreRepository(voldemort.server.StoreRepository) File(java.io.File) MockTime(voldemort.MockTime) Before(org.junit.Before)

Aggregations

SchedulerService (voldemort.common.service.SchedulerService)11 Date (java.util.Date)4 Before (org.junit.Before)4 MockTime (voldemort.MockTime)4 File (java.io.File)3 Properties (java.util.Properties)3 ClientConfig (voldemort.client.ClientConfig)3 SystemStoreRepository (voldemort.client.SystemStoreRepository)3 VoldemortServer (voldemort.server.VoldemortServer)3 ArrayList (java.util.ArrayList)2 Callable (java.util.concurrent.Callable)2 Test (org.junit.Test)2 SystemStoreClientFactory (voldemort.client.SystemStoreClientFactory)2 AsyncMetadataVersionManager (voldemort.client.scheduler.AsyncMetadataVersionManager)2 StoreRepository (voldemort.server.StoreRepository)2 VoldemortConfig (voldemort.server.VoldemortConfig)2 DataCleanupJob (voldemort.server.scheduler.DataCleanupJob)2 ScanPermitWrapper (voldemort.server.storage.ScanPermitWrapper)2 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)2 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)2