/** * Convert Titan internal Mutation representation into HBase native commands. * * @param mutations Mutations to convert into HBase commands. * @param putTimestamp The timestamp to use for Put commands. * @param delTimestamp The timestamp to use for Delete commands. * @return Commands sorted by key converted from Titan internal representation. */ private static Map<ByteBuffer, Pair<Put, Delete>> convertToCommands( Map<String, Map<ByteBuffer, KCVMutation>> mutations, final long putTimestamp, final long delTimestamp) { Map<ByteBuffer, Pair<Put, Delete>> commandsPerKey = new HashMap<ByteBuffer, Pair<Put, Delete>>(); for (Map.Entry<String, Map<ByteBuffer, KCVMutation>> entry : mutations.entrySet()) { byte[] cfName = entry.getKey().getBytes(); for (Map.Entry<ByteBuffer, KCVMutation> m : entry.getValue().entrySet()) { ByteBuffer key = m.getKey(); KCVMutation mutation = m.getValue(); Pair<Put, Delete> commands = commandsPerKey.get(key); if (commands == null) { commands = new Pair<Put, Delete>(); commandsPerKey.put(key, commands); } if (mutation.hasDeletions()) { if (commands.getSecond() == null) commands.setSecond(new Delete(ByteBufferUtil.getArray(key), delTimestamp, null)); for (ByteBuffer b : mutation.getDeletions()) { commands.getSecond().deleteColumns(cfName, ByteBufferUtil.getArray(b), delTimestamp); } } if (mutation.hasAdditions()) { if (commands.getFirst() == null) commands.setFirst(new Put(ByteBufferUtil.getArray(key), putTimestamp)); for (Entry e : mutation.getAdditions()) { commands .getFirst() .add( cfName, ByteBufferUtil.getArray(e.getColumn()), putTimestamp, ByteBufferUtil.getArray(e.getValue())); } } } } return commandsPerKey; }
public HBaseStoreManager(org.apache.commons.configuration.Configuration config) throws StorageException { super(config, PORT_DEFAULT); this.tableName = config.getString(TABLE_NAME_KEY, TABLE_NAME_DEFAULT); this.hconf = HBaseConfiguration.create(); for (Map.Entry<String, String> confEntry : HBASE_CONFIGURATION.entrySet()) { if (config.containsKey(confEntry.getKey())) { hconf.set(confEntry.getValue(), config.getString(confEntry.getKey())); } } // Copy a subset of our commons config into a Hadoop config org.apache.commons.configuration.Configuration hbCommons = config.subset(HBASE_CONFIGURATION_NAMESPACE); @SuppressWarnings("unchecked") // I hope commons-config eventually fixes this Iterator<String> keys = hbCommons.getKeys(); int keysLoaded = 0; while (keys.hasNext()) { String key = keys.next(); String value = hbCommons.getString(key); logger.debug("HBase configuration: setting {}={}", key, value); hconf.set(key, value); keysLoaded++; } logger.debug("HBase configuration: set a total of {} configuration values", keysLoaded); connectionPool = new HTablePool(hconf, connectionPoolSize); openStores = new ConcurrentHashMap<String, HBaseKeyColumnValueStore>(); // TODO: allowing publicly mutate fields is bad, should be fixed features = new StoreFeatures(); features.supportsScan = true; features.supportsBatchMutation = true; features.supportsTransactions = false; features.supportsConsistentKeyOperations = true; features.supportsLocking = false; features.isKeyOrdered = false; features.isDistributed = true; features.hasLocalKeyPartition = false; }