use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class FDBDirectory method listAllInternal.
private List<String> listAllInternal() {
// A private form of the method to allow easier instrumentation
List<String> outList = new ArrayList<>();
List<String> displayList = null;
long totalSize = 0L;
long actualTotalSize = 0L;
for (KeyValue kv : context.ensureActive().getRange(metaSubspace.range())) {
String name = metaSubspace.unpack(kv.getKey()).getString(0);
outList.add(name);
final FDBLuceneFileReference fileReference = FDBLuceneFileReference.parseFromBytes(LuceneSerializer.decode(kv.getValue()));
// Only composite files are prefetched.
if (name.endsWith(".cfs")) {
try {
readBlock(name, CompletableFuture.completedFuture(fileReference), 0);
} catch (RecordCoreException e) {
LOGGER.warn(getLogMessage("Exception thrown during prefetch", LogMessageKeys.FILE_NAME, name));
}
}
this.fileReferenceCache.put(name, fileReference);
if (LOGGER.isDebugEnabled()) {
if (displayList == null) {
displayList = new ArrayList<>();
}
if (kv.getValue() != null) {
displayList.add(name + "(" + fileReference.getSize() + ")");
totalSize += fileReference.getSize();
actualTotalSize += fileReference.getActualSize();
}
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(getLogMessage("listAllFiles", LogMessageKeys.FILE_COUNT, outList.size(), LogMessageKeys.FILE_LIST, displayList, LogMessageKeys.FILE_TOTAL_SIZE, totalSize, LogMessageKeys.FILE_ACTUAL_TOTAL_SIZE, actualTotalSize));
}
return outList;
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class LuceneSerializer method compressIfNeeded.
@Nonnull
private static byte[] compressIfNeeded(boolean compressionNeeded, @Nonnull byte[] data, @Nonnull ByteBuffersDataOutput encodedDataOutput, @Nonnull EncodingState state, int offset) {
if (!compressionNeeded) {
return fallBackToUncompressed(encodedDataOutput.toArrayCopy(), data, state, offset);
}
try (Compressor compressor = CompressionMode.HIGH_COMPRESSION.newCompressor()) {
encodedDataOutput.writeByte(COMPRESSION_VERSION_FOR_HIGH_COMPRESSION);
encodedDataOutput.writeVInt(data.length);
compressor.compress(data, 0, data.length, encodedDataOutput);
final byte[] compressedData = encodedDataOutput.toArrayCopy();
// Compress only if it helps to shorten the bytes
if (compressedData.length < data.length) {
state.setCompressed(true);
return compressedData;
} else {
return fallBackToUncompressed(compressedData, data, state, offset);
}
} catch (Exception e) {
throw new RecordCoreException("Lucene data compression failure", e);
}
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class SynonymMapRegistryImpl method buildSynonymMap.
private static SynonymMap buildSynonymMap(final SynonymMapConfig config) {
try {
SynonymMap.Parser parser = new SolrSynonymParser(true, true, new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String fieldName) {
final StandardTokenizer src = new StandardTokenizer();
TokenStream tok = new LowerCaseFilter(src);
tok = new FlattenGraphFilter(tok);
return new TokenStreamComponents(src, tok);
}
});
parser.parse(new InputStreamReader(config.getSynonymInputStream(), StandardCharsets.UTF_8));
return parser.build();
} catch (IOException | ParseException ex) {
throw new RecordCoreException("Failed to build synonym map", ex).addLogInfo(LogMessageKeys.SYNONYM_NAME, config.getName());
}
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreTest method unionFieldUpdateCompatibility.
@Test
public void unionFieldUpdateCompatibility() throws Exception {
final TestRecords1Proto.MySimpleRecord record1 = TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1066L).setNumValue2(42).build();
final TestRecords1Proto.MySimpleRecord record2 = TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1415L).setStrValueIndexed("second_record").build();
final TestRecords1Proto.MySimpleRecord record3 = TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(800L).setNumValue2(14).build();
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
RecordMetaData metaData = recordStore.getRecordMetaData();
assertSame(TestRecords1Proto.RecordTypeUnion.getDescriptor().findFieldByName("_MySimpleRecord"), metaData.getUnionFieldForRecordType(metaData.getRecordType("MySimpleRecord")));
// Save a record using the field using the old meta-data
recordStore.saveRecord(record1);
// Save a record using the new union descriptor but in the old location
context.ensureActive().set(recordStore.recordsSubspace().pack(Tuple.from(record2.getRecNo(), SplitHelper.UNSPLIT_RECORD)), TestRecordsDuplicateUnionFields.RecordTypeUnion.newBuilder().setMySimpleRecordOld(record2).build().toByteArray());
// Save a record using the new union descriptor in the new location
context.ensureActive().set(recordStore.recordsSubspace().pack(Tuple.from(record3.getRecNo(), SplitHelper.UNSPLIT_RECORD)), TestRecordsDuplicateUnionFields.RecordTypeUnion.newBuilder().setMySimpleRecordNew(record3).build().toByteArray());
assertEquals(record1, recordStore.loadRecord(Tuple.from(record1.getRecNo())).getRecord());
assertEquals(record2, recordStore.loadRecord(Tuple.from(record2.getRecNo())).getRecord());
RecordCoreException e = assertThrows(RecordCoreException.class, () -> recordStore.loadRecord(Tuple.from(record3.getRecNo())).getRecord());
assertNotNull(e.getCause());
assertThat(e.getCause(), instanceOf(RecordSerializationException.class));
assertThat(e.getCause().getMessage(), containsString("because there are unknown fields"));
commit(context);
}
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, metaDataBuilder -> metaDataBuilder.updateRecords(TestRecordsDuplicateUnionFields.getDescriptor()));
RecordMetaData metaData = recordStore.getRecordMetaData();
assertSame(TestRecordsDuplicateUnionFields.RecordTypeUnion.getDescriptor().findFieldByName("_MySimpleRecord_new"), metaData.getUnionFieldForRecordType(metaData.getRecordType("MySimpleRecord")));
// All three records should be readable even though written by the previous store
for (TestRecords1Proto.MySimpleRecord record : Arrays.asList(record1, record2, record3)) {
FDBStoredRecord<Message> storedRecord = recordStore.loadRecord(Tuple.from(record.getRecNo()));
assertNotNull(storedRecord);
assertSame(metaData.getRecordType("MySimpleRecord"), storedRecord.getRecordType());
assertEquals(record, storedRecord.getRecord());
}
commit(context);
}
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method mutateFile.
@Nonnull
static FileDescriptor mutateFile(@Nonnull FileDescriptor originalFile, @Nonnull Consumer<DescriptorProtos.FileDescriptorProto.Builder> fileMutation) {
DescriptorProtos.FileDescriptorProto.Builder fileBuilder = originalFile.toProto().toBuilder();
fileMutation.accept(fileBuilder);
try {
return FileDescriptor.buildFrom(fileBuilder.build(), new FileDescriptor[] { RecordMetaDataOptionsProto.getDescriptor() });
} catch (Descriptors.DescriptorValidationException e) {
throw new RecordCoreException("unable to build file descriptor", e);
}
}
Aggregations