您可能会想到的一些解决方案:1.在条件为rowkey == SiteIdArticleId
的情况下,每个站点进行多个并发搜索。如果您的网站数量相对较少,则此方法会快速运行。2.进行custom secondary index
。第二个索引表,其中AtricleId作为rowkey,SiteIds作为Sell值。3.使用Apache Phoenix
开箱即可进行二级索引。 (但是先检查是否适合需要)
在第二种情况下,您可以从索引表中按键执行get,然后从第一个get中为每个单元格执行从零到多个get的操作。这将非常快地运行,但是需要一些空间开销。
第二个选项,更多详细信息:
假设您的表排序为SiteToArticle
,第二个表排序为ArticleToSite
当您执行写操作时,您会像平时一样将两个表都写入第一个表,并像{"rowkey"=ArticleId, "SiteId"=siteId}
写入第二个表[读取时,首先从ArticleToSite
中读取,然后遍历每个SiteId
,使用键SiteId:ArticleId
创建新的get,然后执行第二批get。代码大概看起来像这样:
byte[] articleId = "ArticleId".getBytes();
Get get = new Get(articleId).readAllVersions();
Table t = connection.getTable(TableName.valueOf("ArticleToSite"));
List<Get> gets = new ArrayList<>();
for (Cell c : t.get(get).getColumnCells("CF".getBytes(), "SiteId".getBytes())) {
byte[] key = Bytes.add(CellUtil.cloneValue(c), ":".getBytes(), articleId);
gets.add(new Get(key));
}
return connection.getTable(TableName.valueOf("SiteToArticle")).get(gets);