我正在尝试以编程方式创建HFiles并将它们加载到正在运行的HBase实例中.我发现很多信息的HFileOutputFormat,并在LoadIncrementalHFiles
我设法创建了新的HFile,将其发送到集群.在群集Web界面中,将显示新的存储文件,但新的键范围不可用.
InputStream stream = ProgrammaticHFileGeneration.class.getResourceAsStream("ga-hourly.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line = null;
Map<byte[], String> rowValues = new HashMap<byte[], String>();
while((line = reader.readLine())!=null) {
String[] vals = line.split(",");
String row = new StringBuilder(vals[0]).append(".").append(vals[1]).append(".").append(vals[2]).append(".").append(vals[3]).toString();
rowValues.put(row.getBytes(), line);
}
List<byte[]> keys = new ArrayList<byte[]>(rowValues.keySet());
Collections.sort(keys, byteArrComparator);
HBaseTestingUtility testingUtility = new HBaseTestingUtility();
testingUtility.startMiniCluster();
testingUtility.createTable("table".getBytes(), "data".getBytes());
Writer writer = new HFile.Writer(testingUtility.getTestFileSystem(),
new Path("/tmp/hfiles/data/hfile"),
HFile.DEFAULT_BLOCKSIZE, Compression.Algorithm.NONE, KeyValue.KEY_COMPARATOR);
for(byte[] key:keys) {
writer.append(new KeyValue(key, "data".getBytes(), "d".getBytes(), rowValues.get(key).getBytes()));
}
writer.appendFileInfo(StoreFile.BULKLOAD_TIME_KEY, Bytes.toBytes(System.currentTimeMillis()));
writer.appendFileInfo(StoreFile.MAJOR_COMPACTION_KEY, Bytes.toBytes(true)); …Run Code Online (Sandbox Code Playgroud) 我为我的实体用户设置了一个objectMapping
RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping mapKeyPath:@"first_name" toAttribute:@"firstName"];
[userMapping mapKeyPath:@"last_name" toAttribute:@"lastName"];
[manager.mappingProvider setMapping:userMapping forKeyPath:@"users"];
[manager.mappingProvider setSerializationMapping:[userMapping inverseMapping] forClass:[User class]];
Run Code Online (Sandbox Code Playgroud)
当应用程序进入后台时我想保存他的个人资料:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[RKObjectManager sharedManager] putObject:currentUser delegate:self];
}
Run Code Online (Sandbox Code Playgroud)
但它不会让我在关闭应用程序时运行请求(我猜不允许新的线程).所以我想同步这样做.
但是,我没有设法用RestKit做到这一点.我身边有一些误会吗?我想拥有:
[[RKObjectManager sharedManager] putObjectSynchronously:currentUser];
Run Code Online (Sandbox Code Playgroud)