2011-11-26 61 views
2
int maxThreads = 300; 
ClientConfig clientConfig = new ClientConfig(); 
clientConfig.setMaxThreads(maxThreads); 
clientConfig.setMaxConnectionsPerNode(maxThreads); 
clientConfig.setConnectionTimeout(500, TimeUnit.MILLISECONDS); 
clientConfig.setBootstrapUrls(env.getVoldemortAddress()); 

StoreClientFactory factory = new SocketStoreClientFactory(clientConfig); 
StoreClient<String, String> client = factory.getStoreClient(env.getPrefixStoreName()); 

現在該怎麼做一次從商店獲取所有鍵值對?如何從voldemort商店一次獲得所有的鍵值對?

回答

3

您必須使用AdminClient來獲取所有密鑰。該類旨在用於有用且經常需要的管理功能,但應該在應用程序級別上謹慎使用(如果有的話)。 See here.

public static void main(String [] args) { 

    String bootStrapUrl = "tcp://localhost:6666"; 
    String storeName = "test"; 

    int maxThreads = 300; 
    ClientConfig clientConfig = new ClientConfig(); 
    clientConfig.setMaxThreads(maxThreads); 
    clientConfig.setMaxConnectionsPerNode(maxThreads); 
    clientConfig.setConnectionTimeout(500, TimeUnit.MILLISECONDS); 
    clientConfig.setBootstrapUrls(bootStrapUrl); 

    StoreClientFactory factory = new SocketStoreClientFactory(clientConfig); 
    StoreClient<String, String> client = factory.getStoreClient(storeName); 

    int nodeId = 0; 
    List<Integer> partitionList = new ArrayList<Integer>(); 
    partitionList.add(0); 
    partitionList.add(1); 
    AdminClient adminClient = new AdminClient(bootStrapUrl, new AdminClientConfig()); 
    Iterator<ByteArray> iterator = adminClient.fetchKeys(nodeId, storeName, partitionList, null); 

    String key = null; 
    String value = null; 
    while (iterator.hasNext()) { 
     key = new String(iterator.next().get()); 
     value = client.getValue(key); 
     System.out.println("Key-Value-Pair::" + key + ":" + value); 
    } 

} 
相關問題