Search in sources :

Example 1 with SchedulerService

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

the class EndToEndRebootstrapTest method setUp.

@Before
public void setUp() throws Exception {
    final int numServers = 2;
    servers = new VoldemortServer[numServers];
    int[][] partitionMap = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };
    cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, partitionMap, socketStoreFactory, // useNio
    true, null, storesXmlfile, new Properties());
    socketUrl = servers[0].getIdentityNode().getSocketUrl().toString();
    bootStrapUrls = new String[1];
    bootStrapUrls[0] = socketUrl;
    Node node = cluster.getNodeById(0);
    String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setClientRegistryUpdateIntervalInSecs(5);
    clientConfig.setAsyncMetadataRefreshInMs(5000);
    clientConfig.setBootstrapUrls(bootstrapUrl);
    SocketStoreClientFactory storeClientFactory = new SocketStoreClientFactory(clientConfig);
    sysRepository = new SystemStoreRepository(clientConfig);
    // Start up the scheduler
    scheduler = new SchedulerService(clientConfig.getAsyncJobThreadPoolSize(), SystemTime.INSTANCE, true);
    storeClient = new ZenStoreClient<String, String>(STORE_NAME, null, storeClientFactory, 3, clientConfig.getClientContextName(), 0, clientConfig, scheduler, sysRepository);
    SystemStoreClientFactory<String, String> systemStoreFactory = new SystemStoreClientFactory<String, String>(clientConfig);
    sysStoreVersion = systemStoreFactory.createSystemStore(SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name());
    clientRegistryStore = systemStoreFactory.createSystemStore(SystemStoreConstants.SystemStoreName.voldsys$_client_registry.name());
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) Node(voldemort.cluster.Node) Properties(java.util.Properties) Before(org.junit.Before)

Example 2 with SchedulerService

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

the class CoordinatorProxyService method initialize.

@Override
protected void initialize() {
    // Initialize the Voldemort Metadata
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setBootstrapUrls(this.coordinatorConfig.getBootstrapURLs());
    storeClientFactory = new SocketStoreClientFactory(clientConfig);
    try {
        initializeAllFatClients();
        // Setup the Async Metadata checker
        SystemStoreRepository sysRepository = new SystemStoreRepository(clientConfig);
        String clusterXml = storeClientFactory.bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);
        sysRepository.createSystemStores(clientConfig, clusterXml, storeClientFactory.getFailureDetector());
        // Create a callback for re-bootstrapping the client
        Callable<Void> rebootstrapCallback = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                initializeAllFatClients();
                return null;
            }
        };
        asyncMetadataManager = new AsyncMetadataVersionManager(sysRepository, rebootstrapCallback, null);
        schedulerService = new SchedulerService(1, SystemTime.INSTANCE, true);
        schedulerService.schedule(asyncMetadataManager.getClass().getName(), asyncMetadataManager, new Date(), this.coordinatorConfig.getMetadataCheckIntervalInMs());
    } catch (BootstrapFailureException be) {
    /*
             * While testing, the cluster may not be up, but we may still need
             * to verify if the service deploys. Hence, catch a
             * BootstrapFailureException if any, but continue to register the
             * Netty service (and listener).
             * 
             * TODO: Modify the coordinator service to be more lazy. If it
             * cannot initialize the fat clients during initialization, do this
             * when we get an actual request.
             */
    }
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) BootstrapFailureException(voldemort.client.BootstrapFailureException) SystemStoreRepository(voldemort.client.SystemStoreRepository) AsyncMetadataVersionManager(voldemort.client.scheduler.AsyncMetadataVersionManager) ClientConfig(voldemort.client.ClientConfig) Callable(java.util.concurrent.Callable) Date(java.util.Date)

Example 3 with SchedulerService

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

the class AsyncOperationTest method testAsyncOperationService.

public void testAsyncOperationService() throws Exception {
    SchedulerService schedulerService = new SchedulerService(2, SystemTime.INSTANCE);
    AsyncOperationService asyncOperationService = new AsyncOperationService(schedulerService, 10);
    final AtomicBoolean op0Complete = new AtomicBoolean(false);
    final AtomicBoolean op1Complete = new AtomicBoolean(false);
    final CountDownLatch op0Latch = new CountDownLatch(1);
    final CountDownLatch op1Latch = new CountDownLatch(1);
    int op0 = asyncOperationService.getUniqueRequestId();
    asyncOperationService.submitOperation(op0, new AsyncOperation(op0, "op0") {

        @Override
        public void operate() throws Exception {
            Thread.sleep(500);
            op0Latch.countDown();
            op0Complete.set(true);
        }

        @Override
        public void stop() {
        }
    });
    int op1 = asyncOperationService.getUniqueRequestId();
    asyncOperationService.submitOperation(op1, new AsyncOperation(op1, "op1") {

        @Override
        public void operate() throws Exception {
            op1Complete.set(true);
            op1Latch.countDown();
        }

        @Override
        public void stop() {
        }
    });
    op1Latch.await();
    List<Integer> opList = asyncOperationService.getAsyncOperationList(false);
    assertFalse("doesn't list completed operations", opList.contains(1));
    assertTrue("lists a pending operation", opList.contains(0));
    opList = asyncOperationService.getAsyncOperationList(true);
    assertTrue("lists all operations", opList.containsAll(Arrays.asList(0, 1)));
    op0Latch.await();
    assertTrue("operation 0 finished", op0Complete.get());
    assertTrue("operation 1 finished", op1Complete.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SchedulerService(voldemort.common.service.SchedulerService) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with SchedulerService

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

the class DataCleanupJobTest method testStoreDeletion.

@Test
public void testStoreDeletion() throws InterruptedException {
    SchedulerService scheduler = new SchedulerService(1, time);
    String cleanUpJobName = "cleanup-freq-test";
    try {
        MockTime mockTime = new MockTime(System.currentTimeMillis());
        ScanPermitWrapper scanWrapper = new ScanPermitWrapper(1);
        // 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);
        // Insert records that should be deleted when the DataCleanUp Job
        // runs
        putWithTimeStamp(0, 10, System.currentTimeMillis() - 8 * Time.MS_PER_DAY);
        Thread.sleep(3 * Time.MS_PER_SECOND);
        // All of them should be deleted.
        assertAbsence(0, 10);
        // Delete the store.
        metadataStore.deleteStoreDefinition(STORE_NAME);
        // Wait 2 seconds to give the Scheduler job, come out of the
        // previous scan if any
        Thread.sleep(2 * Time.MS_PER_SECOND);
        // Intermittent failure, means problem with the code which needs to be fixed.
        for (int i = 0; i < 1000; i++) {
            assertEquals("Deleted store should never acquire a scan permit", 1, scanWrapper.availablePermits());
        }
    } 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 5 with SchedulerService

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

the class AsyncMetadataVersionManagerTest method setUp.

@Before
public void setUp() throws Exception {
    servers = new VoldemortServer[cluster.getNodeIds().size()];
    int i = 0;
    for (Integer nodeId : cluster.getNodeIds()) {
        VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, nodeId, TestUtils.createTempDir().getAbsolutePath(), cluster, storeDefs, new Properties());
        VoldemortServer server = ServerTestUtils.startVoldemortServer(socketStoreFactory, config);
        servers[i++] = server;
    }
    socketUrl = servers[0].getIdentityNode().getSocketUrl().toString();
    bootStrapUrls = new String[1];
    bootStrapUrls[0] = socketUrl;
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setBootstrapUrls(bootStrapUrls).setClientZoneId(clientZoneId);
    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);
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) SystemStoreClientFactory(voldemort.client.SystemStoreClientFactory) SystemStoreRepository(voldemort.client.SystemStoreRepository) Properties(java.util.Properties) VoldemortServer(voldemort.server.VoldemortServer) ClientConfig(voldemort.client.ClientConfig) VoldemortConfig(voldemort.server.VoldemortConfig) 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