use of org.apache.hadoop.hbase.client.HTableInterface in project Solbase by Photobucket.
the class SolbaseUtil method generateDocId.
// sequence generator for generating doc id
public static int generateDocId(String key) throws IOException {
HTableInterface sequence = SolbaseUtil.getSequenceTable();
HTableInterface docIdKeyMap = SolbaseUtil.getDocKeyIdMapTable();
try {
int docId = new Long(sequence.incrementColumnValue(Bytes.toBytes("sequence"), Bytes.toBytes("id"), Bytes.toBytes(""), 1, true)).intValue();
Put mapping = new Put(Bytes.toBytes(key));
mapping.add(Bytes.toBytes("docId"), Bytes.toBytes(""), Bytes.toBytes(docId));
docIdKeyMap.put(mapping);
return docId;
} finally {
SolbaseUtil.releaseTable(sequence);
SolbaseUtil.releaseTable(docIdKeyMap);
}
}
use of org.apache.hadoop.hbase.client.HTableInterface in project Solbase by Photobucket.
the class IndexWriter method deleteDocument.
public void deleteDocument(Put documentPut) {
HTableInterface docTable = SolbaseUtil.getDocTable();
try {
documentPut.add(SolbaseUtil.timestampColumnFamilyName, SolbaseUtil.tombstonedColumnFamilyQualifierBytes, Bytes.toBytes(1));
docTable.put(documentPut);
} catch (IOException e) {
e.printStackTrace();
} finally {
SolbaseUtil.releaseTable(docTable);
}
}
use of org.apache.hadoop.hbase.client.HTableInterface in project Solbase by Photobucket.
the class IndexWriter method updateTermVectorVersionId.
public void updateTermVectorVersionId(TermDocMetadata termDocMeta, int startDocId, int endDocId) {
HTableInterface versionIdTable = SolbaseUtil.getTermVectorVersionIDTable();
Term term = termDocMeta.getTerm();
byte[] fieldTermKey = SolbaseUtil.generateTermKey(term);
Put updatePut = new Put(Bytes.add(fieldTermKey, Bytes.toBytes(startDocId), Bytes.toBytes(endDocId)));
if (termDocMeta.versionIdentifier == null) {
// we havn't loaded this term into cache yet, but need to do update with
try {
TermDocMetadataVersionIdentifier versionIdentifier = TermDocMetadataLoader.getStaticVersionIdentifier(term, startDocId, endDocId);
updatePut.add(SolbaseUtil.timestampColumnFamilyName, Bytes.toBytes(""), Bytes.toBytes(versionIdentifier.getVersionIdentifier()));
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
updatePut.add(SolbaseUtil.timestampColumnFamilyName, Bytes.toBytes(""), Bytes.toBytes(termDocMeta.versionIdentifier.getVersionIdentifier()));
}
try {
versionIdTable.put(updatePut);
} catch (IOException e) {
e.printStackTrace();
} finally {
SolbaseUtil.releaseTable(versionIdTable);
}
}
use of org.apache.hadoop.hbase.client.HTableInterface in project Solbase by Photobucket.
the class IndexWriter method deleteTermVectorVersionId.
public void deleteTermVectorVersionId(TermDocMetadata termDocMeta) {
HTableInterface versionIdTable = SolbaseUtil.getTermVectorVersionIDTable();
Term term = termDocMeta.getTerm();
byte[] fieldTermKey = SolbaseUtil.generateTermKey(term);
Delete delete = new Delete(fieldTermKey);
try {
versionIdTable.delete(delete);
} catch (IOException e) {
e.printStackTrace();
} finally {
SolbaseUtil.releaseTable(versionIdTable);
}
}
use of org.apache.hadoop.hbase.client.HTableInterface in project Solbase by Photobucket.
the class IndexWriter method addDocument.
public void addDocument(Put documentPut, Document doc) {
byte[] docId = documentPut.getRow();
String uniqId = doc.get("global_uniq_id");
if (uniqId != null && docId != null) {
// for remote server update via solr update, we want to use
// getDocTable(), but for now map/red can use local htable
HTableInterface docTable = SolbaseUtil.getDocTable();
// insert document to doctable
try {
documentPut.add(SolbaseUtil.timestampColumnFamilyName, SolbaseUtil.tombstonedColumnFamilyQualifierBytes, Bytes.toBytes(0));
docTable.put(documentPut);
} catch (IOException e) {
throw new SolbaseException(SolbaseException.ErrorCode.SERVER_ERROR, e.getMessage());
} finally {
SolbaseUtil.releaseTable(docTable);
}
// need to insert to docKeyIdMap
Put mapping = new Put(Bytes.toBytes(uniqId));
mapping.add(Bytes.toBytes("docId"), Bytes.toBytes(""), SolbaseUtil.randomize(docId));
mapping.add(SolbaseUtil.docIdColumnFamilyName, SolbaseUtil.tombstonedColumnFamilyQualifierBytes, Bytes.toBytes(0));
updateDocKeyIdMap(mapping);
logger.info("adding document: " + Bytes.toInt(SolbaseUtil.randomize(docId)) + " uniqId: " + uniqId);
} else {
if (uniqId == null) {
logger.info("uniqId is null: " + doc.toString());
} else if (docId == null) {
logger.info("docId is null: " + doc.toString());
} else {
logger.info("both uniqId and docId are null: " + doc.toString());
}
}
}
Aggregations