@Override public BigInteger compose(ByteBuffer bytes) { return new BigInteger(ByteBufferUtil.getArray(bytes)); }
public static BigInteger md5hash(ByteBuffer data) { byte[] result = FBUtilities.hash(data); BigInteger hash = new BigInteger(result); return hash.abs(); }
@Override public ByteBuffer getValue(Cell element) { return org.apache.cassandra.utils.ByteBufferUtil.clone(element.value()); }
public static String readSchemaXML(String indexName) throws IOException { ByteBuffer schema = readCoreResource(indexName, CassandraUtils.schemaKey); //Schema resource not found for the core if (schema == null) { throw new IOException(String.format("invalid core '%s'", indexName)); } return ByteBufferUtil.string(schema); }
@Override public void collect(int docNumber) throws IOException { deleteLucandraDocument(indexName, docNumber, autoCommit); numRemoved.incrementAndGet(); //delete the id reference rm.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, ByteBufferUtil.bytes(Integer.toString(docNumber))), System.currentTimeMillis()-1); }
@Override @SuppressWarnings("unchecked") public IPartitioner getCassandraPartitioner() throws BackendException { Cluster cl = clusterContext.getClient(); try { return FBUtilities.newPartitioner(cl.describePartitioner()); } catch (ConnectionException e) { throw new TemporaryBackendException(e); } catch (ConfigurationException e) { throw new PermanentBackendException(e); } }
private InetAddress getIndexLocation(String subIndex) { ByteBuffer indexName = CassandraUtils.hashBytes(subIndex.getBytes()); List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(CassandraUtils.keySpace, indexName); if (endpoints.isEmpty()) throw new RuntimeException("Unable to find a live endpoint for: " + subIndex); DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getLocalAddress(), endpoints); if (endpoints.contains(FBUtilities.getLocalAddress())) return FBUtilities.getLocalAddress(); return endpoints.get(0); }
private Pair<AtomicInteger, ConcurrentLinkedQueue<RowMutation>> getMutationQueue(String indexName) { Pair<AtomicInteger, ConcurrentLinkedQueue<RowMutation>> mutationQ = mutationList.get(indexName); if (mutationQ == null) { mutationQ = new Pair<AtomicInteger, ConcurrentLinkedQueue<RowMutation>>(new AtomicInteger(0), new ConcurrentLinkedQueue<RowMutation>()); Pair<AtomicInteger, ConcurrentLinkedQueue<RowMutation>> liveQ = mutationList .putIfAbsent(indexName, mutationQ); if (liveQ != null) mutationQ = liveQ; } return mutationQ; }
@Override public BigIntegerToken getToken(ByteBuffer key) { ByteBuffer extractedToken = extractSolandraToken(key); if(extractedToken == null) return super.getToken(key); //the token is pre-processed try { return new BigIntegerToken(ByteBufferUtil.string(extractedToken)); } catch (CharacterCodingException e) { throw new RuntimeException(e); } }
@Override public InputStream openResource(String resourceName) { ByteBuffer resourceValue = null; try { resourceValue = SolandraCoreContainer.readCoreResource(coreName, resourceName); } catch (Exception e) { throw new RuntimeException("Error opening " + resourceName, e); } //fallback to solr.home if (resourceValue == null) { return super.openResource(resourceName); } else { return new ByteArrayInputStream(ByteBufferUtil.getArray(resourceValue)); } } }
@Override public ByteBuffer getColumn(Cell element) { return org.apache.cassandra.utils.ByteBufferUtil.clone(element.name().toByteBuffer()); }
@Override @SuppressWarnings("unchecked") public IPartitioner getCassandraPartitioner() throws BackendException { CTConnection conn = null; try { conn = pool.borrowObject(SYSTEM_KS); return FBUtilities.newPartitioner(conn.getClient().describe_partitioner()); } catch (Exception e) { throw new TemporaryBackendException(e); } finally { pool.returnObjectUnsafe(SYSTEM_KS, conn); } }
public String getToken() { if (StorageService.instance.isClientMode()) return CassandraUtils.fakeToken; return StorageService.instance.getTokenMetadata().getToken(FBUtilities.getLocalAddress()).toString(); }
@Override public org.apache.cassandra.db.DecoratedKey<BigIntegerToken> decorateKey(ByteBuffer key) { ByteBuffer extractedToken = extractSolandraToken(key); //non-solandra key passes through if(extractedToken == null) return new org.apache.cassandra.db.DecoratedKey<BigIntegerToken>(super.getToken(key), key); //the token is pre-processed try { return new org.apache.cassandra.db.DecoratedKey<BigIntegerToken>(new BigIntegerToken(ByteBufferUtil.string(extractedToken)), key); } catch (CharacterCodingException e) { throw new RuntimeException(e); } }
public RowMutation getIdMutation(String indexName, String key, Long id) throws IOException { int shard = getShardFromDocId(id); ByteBuffer idCol = ByteBufferUtil.bytes(String.valueOf(getShardedDocId(id))); ByteBuffer keyCol = ByteBuffer.wrap(key.getBytes("UTF-8")); // Permanently mark the id as taken ByteBuffer idKey = CassandraUtils.hashKeyBytes((indexName + "~" + shard).getBytes("UTF-8"), CassandraUtils.delimeterBytes, "ids".getBytes("UTF-8")); RowMutation rm = new RowMutation(CassandraUtils.keySpace, idKey); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, idCol, ByteBuffer .wrap(getToken().getBytes("UTF-8"))), keyCol, System.currentTimeMillis()); return rm; }
/** Read the object from bytes string. */ public static DocumentMetadata fromBytesUsingThrift(ByteBuffer data) throws IOException { DocumentMetadata docMeta = new DocumentMetadata(); byte[] decompressedData = CassandraUtils.decompress(ByteBufferUtil.getArray(data)); TTransport trans = new TMemoryInputTransport(decompressedData); TProtocol deser = protocolFactory.getProtocol(trans); try { docMeta.read(deser); } catch (TException e) { throw new IOException(e); } return docMeta; } }
@Override protected Object createValue(IndexReader reader, Entry entryKey) throws IOException { String field = StringHelper.intern(entryKey.field); final String[] retArray = new String[reader.maxDoc()]; Collection<IColumn> fcEntries = getFieldCacheEntries(reader, field); for (IColumn col : fcEntries) { if (col instanceof DeletedColumn) continue; int docId = CassandraUtils.readVInt(col.name()); String val = ByteBufferUtil.string(col.value()); retArray[docId] = val; } return retArray; } }
long termval = parser.parseLong(ByteBufferUtil.string(col.value()));
double termval = parser.parseDouble(ByteBufferUtil.string(col.value()));