Skip to content

Commit

Permalink
get node failover working at least minimally
Browse files Browse the repository at this point in the history
  • Loading branch information
readams committed Jun 12, 2009
1 parent ba9282e commit 5e52308
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 7 additions & 5 deletions bindings/cpp/src/RoutedStore.cpp
Expand Up @@ -35,8 +35,8 @@ RoutedStore::RoutedStore(const std::string& storeName,
shared_ptr<std::map<int, shared_ptr<Store> > >& map,
shared_ptr<threadpool::pool>& pool,
shared_ptr<RoutingStrategy>& routingStrat)
: name(storeName), cluster(clust), clusterMap(map), threadPool(pool),
routingStrategy(routingStrat) {
: name(storeName), clientConfig(config), cluster(clust), clusterMap(map),
threadPool(pool), routingStrategy(routingStrat) {

}

Expand All @@ -54,6 +54,8 @@ static bool doGetFromStore(const std::string& key,
node->setAvailable(true);
return true;
} catch (UnreachableStoreException& e) {
/* XXX - TODO add real logging */
std::cerr << "WARNING: Could not read node: " << e.what() << std::endl;
node->setAvailable(false);
}
return false;
Expand Down Expand Up @@ -88,7 +90,7 @@ std::list<VersionedValue>* RoutedStore::get(const std::string& key) {
}

throw InsufficientOperationalNodesException("Could not reach any "
"node for operation");
"node for get operation");
}

static bool doPutFromStore(const std::string& key,
Expand Down Expand Up @@ -133,7 +135,7 @@ void RoutedStore::put(const std::string& key, const VersionedValue& value) {
}

throw InsufficientOperationalNodesException("Could not reach any "
"node for operation");
"node for put operation");
}

static bool doDeleteFromStore(const std::string& key,
Expand Down Expand Up @@ -180,7 +182,7 @@ bool RoutedStore::deleteKey(const std::string& key, const Version& version) {
}

throw InsufficientOperationalNodesException("Could not reach any "
"node for operation");
"node for delete operation");
}

const std::string* RoutedStore::getName() {
Expand Down
2 changes: 1 addition & 1 deletion bindings/cpp/src/include/RoutedStore.h
Expand Up @@ -71,8 +71,8 @@ class RoutedStore: public Store

private:
std::string name;
shared_ptr<Cluster> cluster;
shared_ptr<ClientConfig> clientConfig;
shared_ptr<Cluster> cluster;
shared_ptr<std::map<int, shared_ptr<Store> > > clusterMap;
shared_ptr<threadpool::pool> threadPool;
shared_ptr<RoutingStrategy> routingStrategy;
Expand Down
19 changes: 15 additions & 4 deletions bindings/cpp/utils/voldemortShell.cpp
Expand Up @@ -34,7 +34,9 @@ int main(int argc, char** argv) {
// cluster. You only need one to be able to use the cluster, but
// more will increase availability when initializing.
list<string> bootstrapUrls;
bootstrapUrls.push_back(string("tcp://localhost:6666"));
for (int i = 1; i < argc; i++) {
bootstrapUrls.push_back(string(argv[i]));
}

// The store name is essentially a namespace on the Voldemort
// cluster
Expand All @@ -53,15 +55,24 @@ int main(int argc, char** argv) {
SocketStoreClientFactory factory(config);

auto_ptr<StoreClient> client(factory.getStoreClient(storeName));
if (!client.get()) {
cerr << "Error could not construct client object" << endl;
}

// Get a value
std::string key("hello");
VersionedValue value(*client->get(&key));
cout << "Value: " << *(value.getValue()) << endl;
const VersionedValue* result = client->get(&key);
VersionedValue value;
if (result) {
value = *result;
cout << "Value: " << *(value.getValue()) << endl;
} else {
cout << "Value not set" << endl;
}

// Modify the value
value.setValue(new string("world!"));

// update the value
client->put(&key, &value);

Expand Down

0 comments on commit 5e52308

Please sign in to comment.