Пример #1
0
 /**
  * Given an Object value, pick a partition to store the data. Currently only String objects can be
  * hashed.
  *
  * @param value The value to hash.
  * @param partitionCount The number of partitions to choose from.
  * @return A value between 0 and partitionCount-1, hopefully pretty evenly distributed.
  */
 static int hashinate(Object value, int partitionCount) {
   if (value instanceof String) {
     String string = (String) value;
     try {
       byte bytes[] = string.getBytes("UTF-8");
       int hashCode = 0;
       int offset = 0;
       for (int ii = 0; ii < bytes.length; ii++) {
         hashCode = 31 * hashCode + bytes[offset++];
       }
       return java.lang.Math.abs(hashCode % partitionCount);
     } catch (UnsupportedEncodingException e) {
       hostLogger.l7dlog(
           Level.FATAL,
           LogKeys.host_TheHashinator_ExceptionHashingString.name(),
           new Object[] {string},
           e);
       HStore.crashDB();
     }
   }
   hostLogger.l7dlog(
       Level.FATAL,
       LogKeys.host_TheHashinator_AttemptedToHashinateNonLongOrString.name(),
       new Object[] {value.getClass().getName()},
       null);
   HStore.crashDB();
   return -1;
 }
Пример #2
0
 @Override
 public void faultOccured(VoltFault fault) {
   System.err.println("Unrecoverable fault occured: " + fault.toString());
   HStore.crashDB();
 }