#include "table/block_fetcher.h"
#include "db/table_properties_collector.h"
-#include "env/composite_env_wrapper.h"
#include "file/file_util.h"
#include "options/options_helper.h"
#include "port/port.h"
#include "port/stack_trace.h"
+#include "rocksdb/db.h"
+#include "rocksdb/file_system.h"
#include "table/block_based/binary_search_index_reader.h"
#include "table/block_based/block_based_table_builder.h"
#include "table/block_based/block_based_table_factory.h"
#include "table/block_based/block_based_table_reader.h"
#include "table/format.h"
#include "test_util/testharness.h"
+#include "utilities/memory_allocators.h"
namespace ROCKSDB_NAMESPACE {
namespace {
-
-class CountedMemoryAllocator : public MemoryAllocator {
- public:
- const char* Name() const override { return "CountedMemoryAllocator"; }
-
- void* Allocate(size_t size) override {
- num_allocations_++;
- return static_cast<void*>(new char[size]);
- }
-
- void Deallocate(void* p) override {
- num_deallocations_++;
- delete[] static_cast<char*>(p);
- }
-
- int GetNumAllocations() const { return num_allocations_; }
- int GetNumDeallocations() const { return num_deallocations_; }
-
- private:
- int num_allocations_ = 0;
- int num_deallocations_ = 0;
-};
-
struct MemcpyStats {
int num_stack_buf_memcpy;
int num_heap_buf_memcpy;
NewFileWriter(table_name, &writer);
// Create table builder.
- ImmutableCFOptions ioptions(options_);
+ ImmutableOptions ioptions(options_);
InternalKeyComparator comparator(options_.comparator);
ColumnFamilyOptions cf_options(options_);
MutableCFOptions moptions(cf_options);
- std::vector<std::unique_ptr<IntTblPropCollectorFactory>> factories;
+ IntTblPropCollectorFactories factories;
std::unique_ptr<TableBuilder> table_builder(table_factory_.NewTableBuilder(
TableBuilderOptions(ioptions, moptions, comparator, &factories,
- compression_type, 0 /* sample_for_compression */,
- CompressionOptions(), false /* skip_filters */,
- kDefaultColumnFamilyName, -1 /* level */),
- 0 /* column_family_id */, writer.get()));
+ compression_type, CompressionOptions(),
+ 0 /* column_family_id */, kDefaultColumnFamilyName,
+ -1 /* level */),
+ writer.get()));
// Build table.
for (int i = 0; i < 9; i++) {
std::string key = ToInternalKey(std::to_string(i));
- std::string value = std::to_string(i);
+ // Append "00000000" to string value to enhance compression ratio
+ std::string value = "00000000" + std::to_string(i);
table_builder->Add(key, value);
}
ASSERT_OK(table_builder->Finish());
ASSERT_EQ(memcpy_stats[i].num_compressed_buf_memcpy,
expected_stats.memcpy_stats.num_compressed_buf_memcpy);
- ASSERT_EQ(heap_buf_allocators[i].GetNumAllocations(),
- expected_stats.buf_allocation_stats.num_heap_buf_allocations);
- ASSERT_EQ(
- compressed_buf_allocators[i].GetNumAllocations(),
- expected_stats.buf_allocation_stats.num_compressed_buf_allocations);
-
- // The allocated buffers are not deallocated until
- // the block content is deleted.
- ASSERT_EQ(heap_buf_allocators[i].GetNumDeallocations(), 0);
- ASSERT_EQ(compressed_buf_allocators[i].GetNumDeallocations(), 0);
- blocks[i].allocation.reset();
- ASSERT_EQ(heap_buf_allocators[i].GetNumDeallocations(),
- expected_stats.buf_allocation_stats.num_heap_buf_allocations);
- ASSERT_EQ(
- compressed_buf_allocators[i].GetNumDeallocations(),
- expected_stats.buf_allocation_stats.num_compressed_buf_allocations);
+ if (kXpressCompression == compression_type) {
+ // XPRESS allocates memory internally, thus does not support for
+ // custom allocator verification
+ continue;
+ } else {
+ ASSERT_EQ(
+ heap_buf_allocators[i].GetNumAllocations(),
+ expected_stats.buf_allocation_stats.num_heap_buf_allocations);
+ ASSERT_EQ(compressed_buf_allocators[i].GetNumAllocations(),
+ expected_stats.buf_allocation_stats
+ .num_compressed_buf_allocations);
+
+ // The allocated buffers are not deallocated until
+ // the block content is deleted.
+ ASSERT_EQ(heap_buf_allocators[i].GetNumDeallocations(), 0);
+ ASSERT_EQ(compressed_buf_allocators[i].GetNumDeallocations(), 0);
+ blocks[i].allocation.reset();
+ ASSERT_EQ(
+ heap_buf_allocators[i].GetNumDeallocations(),
+ expected_stats.buf_allocation_stats.num_heap_buf_allocations);
+ ASSERT_EQ(compressed_buf_allocators[i].GetNumDeallocations(),
+ expected_stats.buf_allocation_stats
+ .num_compressed_buf_allocations);
+ }
}
}
}
void NewFileWriter(const std::string& filename,
std::unique_ptr<WritableFileWriter>* writer) {
std::string path = Path(filename);
- EnvOptions env_options;
- std::unique_ptr<WritableFile> file;
- ASSERT_OK(env_->NewWritableFile(path, &file, env_options));
- writer->reset(new WritableFileWriter(
- NewLegacyWritableFileWrapper(std::move(file)), path, env_options));
+ FileOptions file_options;
+ ASSERT_OK(WritableFileWriter::Create(env_->GetFileSystem(), path,
+ file_options, writer, nullptr));
}
void NewFileReader(const std::string& filename, const FileOptions& opt,
std::string path = Path(filename);
std::unique_ptr<FSRandomAccessFile> f;
ASSERT_OK(fs_->NewRandomAccessFile(path, opt, &f, nullptr));
- reader->reset(new RandomAccessFileReader(std::move(f), path, env_));
+ reader->reset(new RandomAccessFileReader(std::move(f), path,
+ env_->GetSystemClock().get()));
}
- void NewTableReader(const ImmutableCFOptions& ioptions,
+ void NewTableReader(const ImmutableOptions& ioptions,
const FileOptions& foptions,
const InternalKeyComparator& comparator,
const std::string& table_name,
MemoryAllocator* compressed_buf_allocator,
BlockContents* contents, MemcpyStats* stats,
CompressionType* compresstion_type) {
- ImmutableCFOptions ioptions(options_);
+ ImmutableOptions ioptions(options_);
ReadOptions roptions;
PersistentCacheOptions persistent_cache_options;
Footer footer;
MemoryAllocator* compressed_buf_allocator,
BlockContents* block, std::string* result,
MemcpyStats* memcpy_stats) {
- ImmutableCFOptions ioptions(options_);
+ ImmutableOptions ioptions(options_);
InternalKeyComparator comparator(options_.comparator);
FileOptions foptions(options_);