Skip to content

Commit

Permalink
move the exceptions in HankResponse down into an exceptions union. (f…
Browse files Browse the repository at this point in the history
…ixed LiveRamp#11)
  • Loading branch information
bryanduxbury committed Apr 21, 2011
1 parent 557e209 commit 79f7ed3
Show file tree
Hide file tree
Showing 11 changed files with 508 additions and 349 deletions.
35 changes: 16 additions & 19 deletions src/hank.thrift
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
namespace java com.rapleaf.hank.generated

union HankResponse {
/** Equivalent to a "null" value */
1: bool not_found;
/** Single-valued result */
2: binary value;
/** Multi-valued result for a single key */
3: list<binary> values;

/** Multi-key multi-value result */
//4: map<binary, binary> multivalues;

// error states

union HankExceptions {
/** The host queried is not assigned the key that was requested */
5: bool wrong_host;
1: bool wrong_host;

/** The domain_id passed in the request does not correspond to a valid domain */
6: bool no_such_domain;
2: bool no_such_domain;

/** There were no available replicas for a given partition */
7: bool zero_replicas;
3: bool zero_replicas;

/** There was some internal error in the server. This is pretty bad. */
8: bool internal_error;
4: string internal_error;
}

union HankResponse {
/** Equivalent to a "null" value */
1: bool not_found;

/** if found, binary result */
2: binary value;

/** error states */
3: HankExceptions xception;
}

service PartDaemon {
HankResponse get(1:i32 domain_id, 2:binary key);

//HankResponse multiget(1:byte domain_id, 2:list<binary> keys);
}

service SmartClient {
Expand Down
13 changes: 8 additions & 5 deletions src/java/com/rapleaf/hank/client/HankSmartClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.rapleaf.hank.coordinator.RingGroupConfig;
import com.rapleaf.hank.coordinator.RingStateChangeListener;
import com.rapleaf.hank.exception.DataNotFoundException;
import com.rapleaf.hank.generated.HankExceptions;
import com.rapleaf.hank.generated.HankResponse;
import com.rapleaf.hank.generated.SmartClient.Iface;

Expand Down Expand Up @@ -133,20 +134,22 @@ public HankResponse get(String domain_name, ByteBuffer key) throws TException {
DomainConfig domainConfig = domainGroup.getDomainConfig(domainId);
partition = domainConfig.getPartitioner().partition(key) % domainConfig.getNumParts();
} catch (DataNotFoundException e) {
return HankResponse.no_such_domain(true);
return HankResponse.xception(HankExceptions.no_such_domain(true));
}

Map<Integer, PartDaemonConnectionSet> domainMap = domainPartToHost.get(domainId);
if (domainMap == null) {
LOG.error(String.format("Got a null domain->part map for domain %s (%d)!", domain_name, domainId));
return HankResponse.internal_error(true);
String errMsg = String.format("Got a null domain->part map for domain %s (%d)!", domain_name, domainId);
LOG.error(errMsg);
return HankResponse.xception(HankExceptions.internal_error(errMsg));
}

PartDaemonConnectionSet hpc = domainMap.get(partition);
if (hpc == null) {
// this is a problem, since the cache must not have been loaded correctly
LOG.error(String.format("Got a null list of hosts for domain %s (%d) when looking for partition %d", domain_name, domainId, partition));
return HankResponse.internal_error(true);
String errMsg = String.format("Got a null list of hosts for domain %s (%d) when looking for partition %d", domain_name, domainId, partition);
LOG.error(errMsg);
return HankResponse.xception(HankExceptions.internal_error(errMsg));
}

return hpc.get(domainId, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.thrift.TException;

import com.rapleaf.hank.generated.HankExceptions;
import com.rapleaf.hank.generated.HankResponse;

public class PartDaemonConnectionSet {
Expand Down Expand Up @@ -49,6 +50,6 @@ public HankResponse get(int domainId, ByteBuffer key) throws TException {
clientBundle.unlock();
}
}
return HankResponse.zero_replicas(true);
return HankResponse.xception(HankExceptions.zero_replicas(true));
}
}
Loading

0 comments on commit 79f7ed3

Please sign in to comment.