mirror of
https://github.com/google/leveldb.git
synced 2024-12-26 03:50:10 +08:00
Sun Studio support, and fix for test related memory fixes.
- LevelDB patch for Sun Studio Based on a patch submitted by Theo Schlossnagle - thanks! This fixes Issue 17. - Fix a couple of test related memory leaks. git-svn-id: https://leveldb.googlecode.com/svn/trunk@38 62dab493-f737-651d-591e-8d6aee1b9529
This commit is contained in:
parent
6699c7ebe6
commit
6872ace901
@ -42,6 +42,7 @@ class SpecialEnv : public EnvWrapper {
|
|||||||
: env_(env),
|
: env_(env),
|
||||||
base_(base) {
|
base_(base) {
|
||||||
}
|
}
|
||||||
|
~SSTableFile() { delete base_; }
|
||||||
Status Append(const Slice& data) { return base_->Append(data); }
|
Status Append(const Slice& data) { return base_->Append(data); }
|
||||||
Status Close() { return base_->Close(); }
|
Status Close() { return base_->Close(); }
|
||||||
Status Flush() { return base_->Flush(); }
|
Status Flush() { return base_->Flush(); }
|
||||||
|
@ -46,7 +46,7 @@ class InternalKey;
|
|||||||
// data structures.
|
// data structures.
|
||||||
enum ValueType {
|
enum ValueType {
|
||||||
kTypeDeletion = 0x0,
|
kTypeDeletion = 0x0,
|
||||||
kTypeValue = 0x1,
|
kTypeValue = 0x1
|
||||||
};
|
};
|
||||||
// kValueTypeForSeek defines the ValueType that should be passed when
|
// kValueTypeForSeek defines the ValueType that should be passed when
|
||||||
// constructing a ParsedInternalKey object for seeking to a particular
|
// constructing a ParsedInternalKey object for seeking to a particular
|
||||||
|
@ -24,7 +24,7 @@ enum FileType {
|
|||||||
kDescriptorFile,
|
kDescriptorFile,
|
||||||
kCurrentFile,
|
kCurrentFile,
|
||||||
kTempFile,
|
kTempFile,
|
||||||
kInfoLogFile, // Either the current one, or an old one
|
kInfoLogFile // Either the current one, or an old one
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the name of the log file with the specified number
|
// Return the name of the log file with the specified number
|
||||||
|
@ -20,7 +20,7 @@ enum RecordType {
|
|||||||
// For fragments
|
// For fragments
|
||||||
kFirstType = 2,
|
kFirstType = 2,
|
||||||
kMiddleType = 3,
|
kMiddleType = 3,
|
||||||
kLastType = 4,
|
kLastType = 4
|
||||||
};
|
};
|
||||||
static const int kMaxRecordType = kLastType;
|
static const int kMaxRecordType = kLastType;
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ class Repairer {
|
|||||||
icmp_(options.comparator),
|
icmp_(options.comparator),
|
||||||
options_(SanitizeOptions(dbname, &icmp_, options)),
|
options_(SanitizeOptions(dbname, &icmp_, options)),
|
||||||
owns_info_log_(options_.info_log != options.info_log),
|
owns_info_log_(options_.info_log != options.info_log),
|
||||||
|
owns_cache_(options_.block_cache != options.block_cache),
|
||||||
next_file_number_(1) {
|
next_file_number_(1) {
|
||||||
// TableCache can be small since we expect each table to be opened once.
|
// TableCache can be small since we expect each table to be opened once.
|
||||||
table_cache_ = new TableCache(dbname_, &options_, 10);
|
table_cache_ = new TableCache(dbname_, &options_, 10);
|
||||||
@ -60,6 +61,9 @@ class Repairer {
|
|||||||
if (owns_info_log_) {
|
if (owns_info_log_) {
|
||||||
delete options_.info_log;
|
delete options_.info_log;
|
||||||
}
|
}
|
||||||
|
if (owns_cache_) {
|
||||||
|
delete options_.block_cache;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Run() {
|
Status Run() {
|
||||||
@ -97,6 +101,7 @@ class Repairer {
|
|||||||
InternalKeyComparator const icmp_;
|
InternalKeyComparator const icmp_;
|
||||||
Options const options_;
|
Options const options_;
|
||||||
bool owns_info_log_;
|
bool owns_info_log_;
|
||||||
|
bool owns_cache_;
|
||||||
TableCache* table_cache_;
|
TableCache* table_cache_;
|
||||||
VersionEdit edit_;
|
VersionEdit edit_;
|
||||||
|
|
||||||
|
@ -238,14 +238,14 @@ class ConcurrentTest {
|
|||||||
current = MakeKey(K, 0);
|
current = MakeKey(K, 0);
|
||||||
} else {
|
} else {
|
||||||
current = iter.key();
|
current = iter.key();
|
||||||
ASSERT_TRUE(IsValidKey(current)) << std::hex << current;
|
ASSERT_TRUE(IsValidKey(current)) << current;
|
||||||
}
|
}
|
||||||
ASSERT_LE(pos, current) << "should not go backwards";
|
ASSERT_LE(pos, current) << "should not go backwards";
|
||||||
|
|
||||||
// Verify that everything in [pos,current) was not present in
|
// Verify that everything in [pos,current) was not present in
|
||||||
// initial_state.
|
// initial_state.
|
||||||
while (pos < current) {
|
while (pos < current) {
|
||||||
ASSERT_LT(key(pos), K) << std::hex << pos;
|
ASSERT_LT(key(pos), K) << pos;
|
||||||
|
|
||||||
// Note that generation 0 is never inserted, so it is ok if
|
// Note that generation 0 is never inserted, so it is ok if
|
||||||
// <*,0,*> is missing.
|
// <*,0,*> is missing.
|
||||||
|
@ -20,7 +20,7 @@ enum Tag {
|
|||||||
kDeletedFile = 6,
|
kDeletedFile = 6,
|
||||||
kNewFile = 7,
|
kNewFile = 7,
|
||||||
// 8 was used for large value refs
|
// 8 was used for large value refs
|
||||||
kPrevLogNumber = 9,
|
kPrevLogNumber = 9
|
||||||
};
|
};
|
||||||
|
|
||||||
void VersionEdit::Clear() {
|
void VersionEdit::Clear() {
|
||||||
|
@ -434,9 +434,14 @@ class VersionSet::Builder {
|
|||||||
|
|
||||||
~Builder() {
|
~Builder() {
|
||||||
for (int level = 0; level < config::kNumLevels; level++) {
|
for (int level = 0; level < config::kNumLevels; level++) {
|
||||||
std::vector<FileMetaData*> to_unref(levels_[level].added_files->begin(),
|
const FileSet* added = levels_[level].added_files;
|
||||||
levels_[level].added_files->end());
|
std::vector<FileMetaData*> to_unref;
|
||||||
delete levels_[level].added_files;
|
to_unref.reserve(added->size());
|
||||||
|
for (FileSet::const_iterator it = added->begin();
|
||||||
|
it != added->end(); ++it) {
|
||||||
|
to_unref.push_back(*it);
|
||||||
|
}
|
||||||
|
delete added;
|
||||||
for (int i = 0; i < to_unref.size(); i++) {
|
for (int i = 0; i < to_unref.size(); i++) {
|
||||||
FileMetaData* f = to_unref[i];
|
FileMetaData* f = to_unref[i];
|
||||||
f->refs--;
|
f->refs--;
|
||||||
|
@ -23,7 +23,7 @@ enum CompressionType {
|
|||||||
// NOTE: do not change the values of existing entries, as these are
|
// NOTE: do not change the values of existing entries, as these are
|
||||||
// part of the persistent format on disk.
|
// part of the persistent format on disk.
|
||||||
kNoCompression = 0x0,
|
kNoCompression = 0x0,
|
||||||
kSnappyCompression = 0x1,
|
kSnappyCompression = 0x1
|
||||||
};
|
};
|
||||||
|
|
||||||
// Options to control the behavior of a database (passed to DB::Open)
|
// Options to control the behavior of a database (passed to DB::Open)
|
||||||
|
@ -72,7 +72,7 @@ class Status {
|
|||||||
kCorruption = 2,
|
kCorruption = 2,
|
||||||
kNotSupported = 3,
|
kNotSupported = 3,
|
||||||
kInvalidArgument = 4,
|
kInvalidArgument = 4,
|
||||||
kIOError = 5,
|
kIOError = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
Code code() const {
|
Code code() const {
|
||||||
|
@ -48,8 +48,9 @@ namespace port {
|
|||||||
// http://msdn.microsoft.com/en-us/library/ms684208(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/ms684208(v=vs.85).aspx
|
||||||
#define LEVELDB_HAVE_MEMORY_BARRIER
|
#define LEVELDB_HAVE_MEMORY_BARRIER
|
||||||
|
|
||||||
// Gcc on x86
|
// Gcc and Sun Studio on x86
|
||||||
#elif defined(__GNUC__) && defined(ARCH_CPU_X86_FAMILY)
|
#elif defined(ARCH_CPU_X86_FAMILY) && \
|
||||||
|
(defined(__GNUC__) || defined(__SUNPRO_CC))
|
||||||
inline void MemoryBarrier() {
|
inline void MemoryBarrier() {
|
||||||
// See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
|
// See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
|
||||||
// this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
|
// this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "leveldb/table.h"
|
#include "leveldb/table.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include "db/dbformat.h"
|
#include "db/dbformat.h"
|
||||||
#include "db/memtable.h"
|
#include "db/memtable.h"
|
||||||
#include "db/write_batch_internal.h"
|
#include "db/write_batch_internal.h"
|
||||||
@ -25,7 +26,11 @@ namespace leveldb {
|
|||||||
// Used to test non-lexicographic comparators.
|
// Used to test non-lexicographic comparators.
|
||||||
static std::string Reverse(const Slice& key) {
|
static std::string Reverse(const Slice& key) {
|
||||||
std::string str(key.ToString());
|
std::string str(key.ToString());
|
||||||
std::string rev(str.rbegin(), str.rend());
|
std::string rev("");
|
||||||
|
for (std::string::reverse_iterator rit = str.rbegin();
|
||||||
|
rit != str.rend(); ++rit) {
|
||||||
|
rev.push_back(*rit);
|
||||||
|
}
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +416,7 @@ enum TestType {
|
|||||||
TABLE_TEST,
|
TABLE_TEST,
|
||||||
BLOCK_TEST,
|
BLOCK_TEST,
|
||||||
MEMTABLE_TEST,
|
MEMTABLE_TEST,
|
||||||
DB_TEST,
|
DB_TEST
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TestArgs {
|
struct TestArgs {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "leveldb/comparator.h"
|
#include "leveldb/comparator.h"
|
||||||
#include "leveldb/slice.h"
|
#include "leveldb/slice.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user