assert columnNames != null;
this.columns = columnNames;
DecoratedKey decoratedKey = ssTable.getPartitioner().decorateKey(key);
FileDataInput file = ssTable.getFileDataInput(decoratedKey, DatabaseDescriptor.getIndexedReadBufferSizeInKB() * 1024);
if (file == null)
return;
try
{
DecoratedKey keyInDisk = ssTable.getPartitioner().convertFromDiskFormat(file.readUTF());
assert keyInDisk.equals(decoratedKey)
: String.format("%s != %s in %s", keyInDisk, decoratedKey, file.getPath());
file.readInt(); // data size
/* Read the bloom filter and index summarizing the columns */
BloomFilter bf = IndexHelper.defreezeBloomFilter(file);
List<IndexHelper.IndexInfo> indexList = IndexHelper.deserializeIndex(file);
cf = ColumnFamily.serializer().deserializeFromSSTableNoColumns(ssTable.makeColumnFamily(), file);
// we can stop early if bloom filter says none of the columns actually exist -- but,
// we can't stop before initializing the cf above, in case there's a relevant tombstone
List<byte[]> filteredColumnNames = new ArrayList<byte[]>(columnNames.size());
for (byte[] name : columnNames)
{
if (bf.isPresent(name))
{
filteredColumnNames.add(name);
}
}
if (filteredColumnNames.isEmpty())
return;
file.readInt(); // column count
/* get the various column ranges we have to read */
AbstractType comparator = ssTable.getColumnComparator();
SortedSet<IndexHelper.IndexInfo> ranges = new TreeSet<IndexHelper.IndexInfo>(IndexHelper.getComparator(comparator));
for (byte[] name : filteredColumnNames)
{
int index = IndexHelper.indexFor(name, indexList, comparator, false);
if (index == indexList.size())
continue;
IndexHelper.IndexInfo indexInfo = indexList.get(index);
if (comparator.compare(name, indexInfo.firstName) < 0)
continue;
ranges.add(indexInfo);
}
file.mark();
for (IndexHelper.IndexInfo indexInfo : ranges)
{
file.reset();
long curOffsert = file.skipBytes((int)indexInfo.offset);
assert curOffsert == indexInfo.offset;
// TODO only completely deserialize columns we are interested in
while (file.bytesPastMark() < indexInfo.offset + indexInfo.width)
{
final IColumn column = cf.getColumnSerializer().deserialize(file);
// we check vs the original Set, not the filtered List, for efficiency
if (columnNames.contains(column.name()))
{
cf.addColumn(column);
}
}
}
}
finally
{
file.close();
}
iter = cf.getSortedColumns().iterator();
}