Search in sources :

Example 1 with SolbaseException

use of org.solbase.common.SolbaseException in project Solbase by Photobucket.

the class IndexWriter method updateDocument.

public void updateDocument(Put documentPut, Document doc) {
    String uniqId = doc.get("global_uniq_id");
    Put mappingPut = new Put(Bytes.toBytes(uniqId));
    mappingPut.add(SolbaseUtil.docIdColumnFamilyName, SolbaseUtil.tombstonedColumnFamilyQualifierBytes, Bytes.toBytes(0));
    updateDocKeyIdMap(mappingPut);
    // 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);
    }
}
Also used : SolbaseException(org.solbase.common.SolbaseException) IOException(java.io.IOException) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Put(org.apache.hadoop.hbase.client.Put)

Example 2 with SolbaseException

use of org.solbase.common.SolbaseException in project Solbase by Photobucket.

the class IndexWriter method deleteTermVector.

/**
	 *
	 * @param termDocMeta - term vector to be deleted
	 * @param startDocId
	 * @param endDocId
	 * @param compare - if true, it will compare new and old term vectors and if same, don't bother deleting term vector
	 * @return boolean - indicating whether term vector's been deleted
	 */
public boolean deleteTermVector(TermDocMetadata termDocMeta, int startDocId, int endDocId, boolean compare) {
    // to update, we should first delete existing term doc meta data.
    // getting terVector and doc tables
    HTableInterface termVectorTable = SolbaseUtil.getTermVectorTable();
    ResultScanner fieldScanner = null;
    try {
        byte[] key = termDocMeta.getFieldTermKey();
        int docNumber = termDocMeta.getDocId();
        Delete delete = null;
        switch(TermDocMetadataLoader.storageType) {
            case KEY_ONLY:
                {
                    byte[] termBeginKey = Bytes.add(key, SolbaseUtil.delimiter, Bytes.toBytes(docNumber));
                    byte[] termEndKey = Bytes.add(key, SolbaseUtil.delimiter, Bytes.toBytes(docNumber + 1));
                    Scan fieldScan = new Scan(termBeginKey, termEndKey);
                    fieldScan.addFamily(SolbaseUtil.termVectorDocColumnFamilyName);
                    fieldScanner = termVectorTable.getScanner(fieldScan);
                    Result termDoc;
                    termDoc = fieldScanner.next();
                    fieldScanner.close();
                    if (termDoc != null && !termDoc.isEmpty()) {
                        if (compare) {
                            byte[] oldRow = termDoc.getRow();
                            ByteBuffer buf = termDocMeta.serialize();
                            byte[] newRow = Bytes.add(Bytes.add(key, SolbaseUtil.delimiter, Bytes.toBytes(docNumber)), Bytes.toBytes(buf));
                            // if term vector hasn't changed, don't bother deleting
                            if (!ArrayUtils.isEquals(oldRow, newRow)) {
                                delete = new Delete(termDoc.getRow());
                            }
                        } else {
                            delete = new Delete(termDoc.getRow());
                        }
                    }
                }
                break;
            case WIDE_ROW:
                int chunkId = TermDocMetadataLoader.getChunkId(docNumber);
                delete = new Delete(Bytes.add(key, SolbaseUtil.delimiter, Bytes.toBytes(chunkId)));
                break;
            case NARROW_ROW:
            default:
                {
                    delete = new Delete(Bytes.add(key, SolbaseUtil.delimiter, Bytes.toBytes(docNumber)));
                }
        }
        if (delete != null) {
            termVectorTable.delete(delete);
            logger.info("deleting term vector: " + termDocMeta.getTerm().toString() + " docId: " + docNumber);
            return true;
        }
    } catch (IOException e) {
        throw new SolbaseException(SolbaseException.ErrorCode.SERVER_ERROR, e.getMessage());
    } finally {
        if (fieldScanner != null) {
            fieldScanner.close();
        }
        SolbaseUtil.releaseTable(termVectorTable);
    }
    return false;
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) SolbaseException(org.solbase.common.SolbaseException) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) IOException(java.io.IOException) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) ByteBuffer(java.nio.ByteBuffer) Result(org.apache.hadoop.hbase.client.Result)

Example 3 with SolbaseException

use of org.solbase.common.SolbaseException in project Solbase by Photobucket.

the class SolbaseIndexWriter method editDoc.

/**
	 * Doing edit logic here. instead of blindingly inserting, we need to compare new doc with old doc and do appropriate modification
	 * to tv and doc
	 * @param newDoc
	 * @param indexName
	 * @return
	 */
public boolean editDoc(Document newDoc, String indexName, int docNumber, boolean updateStore) {
    try {
        CachedObjectWrapper<Document, Long> cachedObj = ReaderCache.getDocument(docNumber, null, indexName, 0, 0);
        if (cachedObj == null || cachedObj.getValue() == null) {
            // document doesn't exist, so let's just bail out here
            return true;
        }
        ParsedDoc parsedDoc = new ParsedDoc(newDoc);
        parsedDoc.setIndexName(indexName);
        parsedDoc.setIndexUtil(indexUtil);
        parsedDoc.setIndexWriter(writer);
        parsedDoc.setUpdateStore(updateStore);
        int shardNum = SolbaseShardUtil.getShardNum(indexName);
        int startDocId = SolbaseShardUtil.getStartDocId(shardNum);
        int endDocId = SolbaseShardUtil.getEndDocId(shardNum);
        ReaderCache.updateDocument(docNumber, parsedDoc, indexName, writer, LayeredCache.ModificationType.UPDATE, updateStore, startDocId, endDocId);
        return true;
    } catch (IOException e) {
        logger.info("edit doc failed: " + docNumber);
        logger.info(e.toString());
    } catch (InterruptedException e) {
        logger.info("edit doc failed: " + docNumber);
        logger.info(e.toString());
    } catch (MemcachedException e) {
        logger.info("edit doc failed: " + docNumber);
        logger.info(e.toString());
    } catch (TimeoutException e) {
        logger.info("edit doc failed: " + docNumber);
        logger.info(e.toString());
    } catch (SolbaseException e) {
        logger.info("edit doc failed: " + docNumber);
        logger.info(e.toString());
    }
    return false;
}
Also used : ParsedDoc(org.solbase.indexer.ParsedDoc) SolbaseException(org.solbase.common.SolbaseException) AtomicLong(java.util.concurrent.atomic.AtomicLong) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) MemcachedException(net.rubyeye.xmemcached.exception.MemcachedException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with SolbaseException

use of org.solbase.common.SolbaseException in project Solbase by Photobucket.

the class SolbaseIndexWriter method delete.

public void delete(DeleteUpdateCommand cmd) throws IOException {
    deleteByIdCommands.incrementAndGet();
    deleteByIdCommandsCumulative.incrementAndGet();
    if (!cmd.fromPending && !cmd.fromCommitted) {
        numErrors.incrementAndGet();
        numErrorsCumulative.incrementAndGet();
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "meaningless command: " + cmd);
    }
    if (!cmd.fromPending || !cmd.fromCommitted) {
        numErrors.incrementAndGet();
        numErrorsCumulative.incrementAndGet();
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "operation not supported" + cmd);
    }
    // Delete all terms/fields/etc
    String indexName = core.getName();
    writer.setIndexName(indexName);
    writer.setIndexUtil(indexUtil);
    int docId = Integer.parseInt(cmd.id);
    logger.info("deleting doc: " + docId);
    try {
        CachedObjectWrapper<Document, Long> wrapper = ReaderCache.getDocument(docId, null, indexName, 0, 0);
        boolean updateStore = cmd.getUpdateStore();
        ParsedDoc parsedDoc = new ParsedDoc();
        parsedDoc.setIndexName(indexName);
        parsedDoc.setIndexUtil(indexUtil);
        parsedDoc.setIndexWriter(writer);
        parsedDoc.setUpdateStore(updateStore);
        int shardNum = SolbaseShardUtil.getShardNum(indexName);
        int startDocId = SolbaseShardUtil.getStartDocId(shardNum);
        int endDocId = SolbaseShardUtil.getEndDocId(shardNum);
        ReaderCache.updateDocument(docId, parsedDoc, indexName, writer, LayeredCache.ModificationType.DELETE, updateStore, startDocId, endDocId);
    } catch (InterruptedException e) {
        logger.info("delete doc failed: " + docId);
        logger.info(e.toString());
    } catch (MemcachedException e) {
        logger.info("delete doc failed: " + docId);
        logger.info(e.toString());
    } catch (TimeoutException e) {
        logger.info("delete doc failed: " + docId);
        logger.info(e.toString());
    } catch (SolbaseException e) {
        logger.info("delete doc failed: " + docId);
        logger.info(e.toString());
    }
}
Also used : ParsedDoc(org.solbase.indexer.ParsedDoc) SolbaseException(org.solbase.common.SolbaseException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Document(org.apache.lucene.document.Document) SolrException(org.apache.solr.common.SolrException) MemcachedException(net.rubyeye.xmemcached.exception.MemcachedException) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with SolbaseException

use of org.solbase.common.SolbaseException in project Solbase by Photobucket.

the class SolbaseIndexWriter method addDoc.

public int addDoc(AddUpdateCommand cmd) throws IOException {
    addCommands.incrementAndGet();
    addCommandsCumulative.incrementAndGet();
    int rc = -1;
    // no duplicates allowed
    SchemaField uniqueField = core.getSchema().getUniqueKeyField();
    if (uniqueField == null)
        throw new IOException("Solbase requires a unique field");
    // if there is no ID field, use allowDups
    if (idField == null) {
        throw new IOException("Solbase requires a unique field");
    }
    try {
        String indexName = core.getName();
        writer.setIndexName(indexName);
        Document doc = cmd.getLuceneDocument(schema);
        String idFieldName = idTerm.field();
        // solbase specific fields. should remove it after using
        boolean updateStore = false;
        String updateVal = doc.get("updateStore");
        if (updateVal != null) {
            // updating hbase after cache is updated
            updateStore = true;
        }
        int docNumber = Integer.parseInt(doc.get(idFieldName));
        // if edit field is present, it's for modification instead of blind add
        String editVal = doc.get("edit");
        // we don't need following fields. only used for update api
        doc.removeField("docId");
        doc.removeField("edit");
        doc.removeField("updateStore");
        // set indexutil to writer
        writer.setIndexUtil(indexUtil);
        String globaId = doc.getField("global_uniq_id").stringValue();
        int shardNum = SolbaseShardUtil.getShardNum(indexName);
        int startDocId = SolbaseShardUtil.getStartDocId(shardNum);
        int endDocId = SolbaseShardUtil.getEndDocId(shardNum);
        if (editVal != null) {
            logger.info("updating doc: " + docNumber);
            if (editDoc(doc, indexName, docNumber, updateStore)) {
                rc = 1;
            }
        } else {
            try {
                logger.info("adding doc: " + docNumber);
                ParsedDoc parsedDoc = writer.parseDoc(doc, schema.getAnalyzer(), indexName, docNumber, indexUtil.getSortFieldNames());
                List<TermDocMetadata> termDocMetas = parsedDoc.getTermDocMetadatas();
                // TODO: possible problem
                // doc is not in cache, cluster isn't responsible for update store
                // doc never gets updated in hbase, nor cache
                // for loop below will update tv with this new doc.
                // when searched, it will throw null point exception on this doc
                // therefore, update store first if adding doc (replication can still cause this issue if back'd up)
                ReaderCache.updateDocument(docNumber, parsedDoc, indexName, writer, LayeredCache.ModificationType.ADD, updateStore, startDocId, endDocId);
                for (TermDocMetadata termDocMeta : termDocMetas) {
                    ReaderCache.updateTermDocsMetadata(termDocMeta.getTerm(), termDocMeta, indexName, writer, LayeredCache.ModificationType.ADD, updateStore, startDocId, endDocId);
                }
                rc = 1;
                logger.info("adding doc: " + docNumber);
            } catch (NumberFormatException e) {
                logger.info("adding doc failed: " + docNumber);
                logger.info(e.toString());
            } catch (InterruptedException e) {
                logger.info("adding doc failed: " + docNumber);
                logger.info(e.toString());
            } catch (MemcachedException e) {
                logger.info("adding doc failed: " + docNumber);
                logger.info(e.toString());
            } catch (TimeoutException e) {
                logger.info("adding doc failed: " + docNumber);
                logger.info(e.toString());
            } catch (SolbaseException e) {
                logger.info("adding doc failed: " + docNumber);
                logger.info(e.toString());
            }
        }
    } finally {
        if (rc != 1) {
            numErrors.incrementAndGet();
            numErrorsCumulative.incrementAndGet();
        }
    }
    return rc;
}
Also used : SolbaseException(org.solbase.common.SolbaseException) TermDocMetadata(org.solbase.lucenehbase.TermDocMetadata) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) SchemaField(org.apache.solr.schema.SchemaField) ParsedDoc(org.solbase.indexer.ParsedDoc) MemcachedException(net.rubyeye.xmemcached.exception.MemcachedException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

SolbaseException (org.solbase.common.SolbaseException)7 IOException (java.io.IOException)6 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)4 TimeoutException (java.util.concurrent.TimeoutException)3 MemcachedException (net.rubyeye.xmemcached.exception.MemcachedException)3 Document (org.apache.lucene.document.Document)3 ParsedDoc (org.solbase.indexer.ParsedDoc)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Delete (org.apache.hadoop.hbase.client.Delete)2 Put (org.apache.hadoop.hbase.client.Put)2 ByteBuffer (java.nio.ByteBuffer)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1 Scan (org.apache.hadoop.hbase.client.Scan)1 SolrException (org.apache.solr.common.SolrException)1 SchemaField (org.apache.solr.schema.SchemaField)1 TermDocMetadata (org.solbase.lucenehbase.TermDocMetadata)1