Search in sources :

Example 11 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory 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 12 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.

the class CoordinatorProxyService method initializeFatClient.

/**
     * Initialize the fat client for the given store.
     * 
     * 1. Updates the coordinatorMetadata 2.Gets the new store configs from the
     * config file 3.Creates a new @SocketStoreClientFactory 4. Subsequently
     * caches the @StoreClient obtained from the factory.
     * 
     * 
     * This is synchronized because if Coordinator Admin is already doing some
     * change we want the AsyncMetadataVersionManager to wait.
     * 
     * @param storeName
     */
private synchronized void initializeFatClient(String storeName, Properties storeClientProps) {
    // updates the coordinator metadata with recent stores and cluster xml
    updateCoordinatorMetadataWithLatestState();
    logger.info("Creating a Fat client for store: " + storeName);
    SocketStoreClientFactory fatClientFactory = getFatClientFactory(this.coordinatorConfig.getBootstrapURLs(), storeClientProps);
    if (this.fatClientMap == null) {
        this.fatClientMap = new HashMap<String, DynamicTimeoutStoreClient<ByteArray, byte[]>>();
    }
    DynamicTimeoutStoreClient<ByteArray, byte[]> fatClient = new DynamicTimeoutStoreClient<ByteArray, byte[]>(storeName, fatClientFactory, 1, this.coordinatorMetadata.getStoreDefs(), this.coordinatorMetadata.getClusterXmlStr());
    this.fatClientMap.put(storeName, fatClient);
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray)

Example 13 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.

the class RebootstrappingStoreTest method setUp.

@Before
public void setUp() throws Exception {
    SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
    int numServers = 2;
    VoldemortServer[] voldemortServers = new VoldemortServer[numServers];
    int[][] partitionMap = { { 0, 1 }, {} };
    cluster = ServerTestUtils.startVoldemortCluster(numServers, voldemortServers, partitionMap, socketStoreFactory, false, null, STORES_XML, new Properties());
    servers = Lists.newArrayList();
    for (int i = 0; i < numServers; ++i) {
        servers.add(voldemortServers[i]);
    }
    String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
    storeClient = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl)).getStoreClient(STORE_NAME);
    Map<String, String> entries = Maps.newHashMap();
    entries.put("a", "1");
    entries.put("b", "2");
    for (Map.Entry<String, String> entry : entries.entrySet()) storeClient.put(entry.getKey(), entry.getValue());
}
Also used : SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) VoldemortServer(voldemort.server.VoldemortServer) Properties(java.util.Properties) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) Map(java.util.Map) Before(org.junit.Before)

Example 14 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.

the class VersionedPutPruneJobTest method setup.

@Before
public void setup() throws Exception {
    socketStoreMap = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
    socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
    final int numServers = 4;
    servers = new VoldemortServer[numServers];
    int[][] currentPartitionMap = { { 0, 4 }, { 2, 6 }, { 1, 5 }, { 3, 7 } };
    cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, currentPartitionMap, socketStoreFactory, true, null, "test/common/voldemort/config/single-store-322.xml", new Properties());
    StringReader reader = new StringReader(VoldemortTestConstants.getSingleStore322Xml());
    StoreDefinition storeDef = new StoreDefinitionsMapper().readStoreList(reader).get(0);
    currentRoutingPlan = new BaseStoreRoutingPlan(cluster, storeDef);
    String bootStrapUrl = "";
    for (VoldemortServer server : servers) {
        Node node = server.getIdentityNode();
        socketStoreMap.put(node.getId(), ServerTestUtils.getSocketStore(socketStoreFactory, "test", node.getHost(), node.getSocketPort(), RequestFormatType.PROTOCOL_BUFFERS, false, true));
        bootStrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
    }
    testEntries = ServerTestUtils.createRandomKeyValueString(100);
    int[][] oldPartitionMap = { { 3, 6 }, { 1, 4 }, { 7, 2 }, { 5, 0 } };
    oldRoutingPlan = new BaseStoreRoutingPlan(ServerTestUtils.getLocalCluster(numServers, oldPartitionMap), storeDef);
    SocketStoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootStrapUrl));
    storeClient = factory.getStoreClient("test");
}
Also used : Node(voldemort.cluster.Node) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Store(voldemort.store.Store) Properties(java.util.Properties) VoldemortServer(voldemort.server.VoldemortServer) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader) BaseStoreRoutingPlan(voldemort.routing.BaseStoreRoutingPlan) ClientConfig(voldemort.client.ClientConfig) Before(org.junit.Before)

Example 15 with SocketStoreClientFactory

use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.

the class VoldemortAvroClientShell method main.

public static void main(String[] args) throws IOException {
    if (args.length < 2 || args.length > 3) {
        System.err.println("Usage: java VoldemortAvroClient store_name bootstrap_url [command_file]");
        System.exit(-1);
    }
    String storeName = args[0];
    String bootstrapUrl = args[1];
    String commandsFileName = "";
    BufferedReader fileReader = null;
    BufferedReader inputReader = null;
    try {
        if (args.length == 3) {
            commandsFileName = args[2];
            fileReader = new BufferedReader(new FileReader(commandsFileName));
        }
        inputReader = new BufferedReader(new InputStreamReader(System.in));
    } catch (IOException e) {
        Utils.croak("Failure to open input stream: " + e.getMessage());
    }
    ClientConfig clientConfig = new ClientConfig().setBootstrapUrls(bootstrapUrl).setEnableLazy(false).setRequestFormatType(RequestFormatType.VOLDEMORT_V3);
    StoreClientFactory factory = null;
    DefaultStoreClient<Object, Object> client = null;
    try {
        try {
            factory = new SocketStoreClientFactory(clientConfig);
            client = (DefaultStoreClient<Object, Object>) factory.getStoreClient(storeName);
        } catch (Exception e) {
            Utils.croak("Could not connect to server: " + e.getMessage());
        }
        System.out.println("Established connection to " + storeName + " via " + bootstrapUrl);
        System.out.print(PROMPT);
        Pair<Schema, Schema> keyValueSchemaPair = getLatestKeyValueSchema(bootstrapUrl, storeName);
        Schema latestKeySchema = keyValueSchemaPair.getFirst();
        if (latestKeySchema == null) {
            Utils.croak("Could not parse latest key schema for store name " + storeName);
        }
        Schema latestValueSchema = keyValueSchemaPair.getSecond();
        if (latestValueSchema == null) {
            Utils.croak("Could not parse latest value schema for store name " + storeName);
        }
        if (fileReader != null) {
            processCommands(client, fileReader, latestKeySchema, latestValueSchema, true);
        } else {
            processCommands(client, inputReader, latestKeySchema, latestValueSchema, false);
        }
    } finally {
        if (factory != null)
            factory.close();
        if (fileReader != null)
            fileReader.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Schema(org.apache.avro.Schema) IOException(java.io.IOException) IOException(java.io.IOException) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ClientConfig(voldemort.client.ClientConfig)

Aggregations

SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)40 ClientConfig (voldemort.client.ClientConfig)37 IOException (java.io.IOException)14 VoldemortServer (voldemort.server.VoldemortServer)14 ByteArray (voldemort.utils.ByteArray)13 Properties (java.util.Properties)12 Before (org.junit.Before)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 StoreClientFactory (voldemort.client.StoreClientFactory)9 Cluster (voldemort.cluster.Cluster)8 HashMap (java.util.HashMap)7 ExecutorService (java.util.concurrent.ExecutorService)7 Node (voldemort.cluster.Node)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 ClusterTestUtils (voldemort.ClusterTestUtils)6 DefaultStoreClient (voldemort.client.DefaultStoreClient)6 InvalidMetadataException (voldemort.store.InvalidMetadataException)6