Attempts to flush the collisions to storage. The storage call is a PUT so it will overwrite any existing columns, but since each column is the TSUID it should only exist once and the data shouldn't change. Note: This will also clear the local #collisions map @param tsdb The TSDB to us
(final TSDB tsdb)
| 1073 | * @throws HBaseException if there was an issue |
| 1074 | */ |
| 1075 | public Deferred<Boolean> flushCollisions(final TSDB tsdb) { |
| 1076 | if (!store_failures) { |
| 1077 | collisions.clear(); |
| 1078 | return Deferred.fromResult(true); |
| 1079 | } |
| 1080 | |
| 1081 | final byte[] row_key = new byte[TREE_ID_WIDTH + 1]; |
| 1082 | System.arraycopy(idToBytes(tree_id), 0, row_key, 0, TREE_ID_WIDTH); |
| 1083 | row_key[TREE_ID_WIDTH] = COLLISION_ROW_SUFFIX; |
| 1084 | |
| 1085 | final byte[][] qualifiers = new byte[collisions.size()][]; |
| 1086 | final byte[][] values = new byte[collisions.size()][]; |
| 1087 | |
| 1088 | int index = 0; |
| 1089 | for (Map.Entry<String, String> entry : collisions.entrySet()) { |
| 1090 | qualifiers[index] = new byte[COLLISION_PREFIX.length + |
| 1091 | (entry.getKey().length() / 2)]; |
| 1092 | System.arraycopy(COLLISION_PREFIX, 0, qualifiers[index], 0, |
| 1093 | COLLISION_PREFIX.length); |
| 1094 | final byte[] tsuid = UniqueId.stringToUid(entry.getKey()); |
| 1095 | System.arraycopy(tsuid, 0, qualifiers[index], |
| 1096 | COLLISION_PREFIX.length, tsuid.length); |
| 1097 | |
| 1098 | values[index] = entry.getValue().getBytes(CHARSET); |
| 1099 | index++; |
| 1100 | } |
| 1101 | |
| 1102 | final PutRequest put = new PutRequest(tsdb.treeTable(), row_key, |
| 1103 | TREE_FAMILY, qualifiers, values); |
| 1104 | collisions.clear(); |
| 1105 | |
| 1106 | /** |
| 1107 | * Super simple callback used to convert the Deferred<Object> to a |
| 1108 | * Deferred<Boolean> so that it can be grouped with other storage |
| 1109 | * calls |
| 1110 | */ |
| 1111 | final class PutCB implements Callback<Deferred<Boolean>, Object> { |
| 1112 | |
| 1113 | @Override |
| 1114 | public Deferred<Boolean> call(Object result) throws Exception { |
| 1115 | return Deferred.fromResult(true); |
| 1116 | } |
| 1117 | |
| 1118 | } |
| 1119 | |
| 1120 | return tsdb.getClient().put(put).addCallbackDeferring(new PutCB()); |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * Attempts to flush the non-matches to storage. The storage call is a PUT so |