Skip to content

Commit

Permalink
Fix build issue. (facebook#1123)
Browse files Browse the repository at this point in the history
Implement GetUniqueIdFromFile to support new tests and the feature.
  • Loading branch information
yuslepukhin authored and igorcanadi committed May 17, 2016
1 parent f6aedb6 commit bac3be7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ set(SOURCES
table/plain_table_index.cc
table/plain_table_key_coding.cc
table/plain_table_reader.cc
persistent_cache_helper.cc
table/persistent_cache_helper.cc
table/table_properties.cc
table/two_level_iterator.cc
tools/sst_dump_tool.cc
Expand Down
49 changes: 46 additions & 3 deletions port/win/env_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "port/win/win_logger.h"

#include "util/random.h"
#include "util/coding.h"
#include "util/iostats_context_imp.h"
#include "util/rate_limiter.h"
#include "util/sync_point.h"
Expand Down Expand Up @@ -54,14 +55,15 @@ std::string GetWindowsErrSz(DWORD err) {
return Err;
}

namespace {

const size_t c_OneMB = (1 << 20);

ThreadStatusUpdater* CreateThreadStatusUpdater() {
return new ThreadStatusUpdater();
}

namespace {

const size_t c_OneMB = (1 << 20);

inline Status IOErrorFromWindowsError(const std::string& context, DWORD err) {
return Status::IOError(context, GetWindowsErrSz(err));
}
Expand Down Expand Up @@ -198,6 +200,31 @@ inline Status ftruncate(const std::string& filename, HANDLE hFile,
return status;
}

size_t GetUniqueIdFromFile(HANDLE hFile, char* id, size_t max_size) {

if (max_size < kMaxVarint64Length * 3) {
return 0;
}

BY_HANDLE_FILE_INFORMATION FileInfo;

BOOL result = GetFileInformationByHandle(hFile, &FileInfo);

TEST_SYNC_POINT_CALLBACK("GetUniqueIdFromFile:FS_IOC_GETVERSION", &result);

if (!result) {
return 0;
}

char* rid = id;
rid = EncodeVarint64(rid, uint64_t(FileInfo.dwVolumeSerialNumber));
rid = EncodeVarint64(rid, uint64_t(FileInfo.nFileIndexHigh));
rid = EncodeVarint64(rid, uint64_t(FileInfo.nFileIndexLow));

assert(rid >= id);
return static_cast<size_t>(rid - id);
}

// mmap() based random-access
class WinMmapReadableFile : public RandomAccessFile {
const std::string fileName_;
Expand Down Expand Up @@ -246,6 +273,10 @@ class WinMmapReadableFile : public RandomAccessFile {
virtual Status InvalidateCache(size_t offset, size_t length) override {
return Status::OK();
}

virtual size_t GetUniqueId(char* id, size_t max_size) const override {
return GetUniqueIdFromFile(hFile_, id, max_size);
}
};

// We preallocate up to an extra megabyte and use memcpy to append new
Expand Down Expand Up @@ -591,6 +622,10 @@ class WinMmapFile : public WritableFile {
}
return status;
}

virtual size_t GetUniqueId(char* id, size_t max_size) const override {
return GetUniqueIdFromFile(hFile_, id, max_size);
}
};

class WinSequentialFile : public SequentialFile {
Expand Down Expand Up @@ -915,6 +950,10 @@ class WinRandomAccessFile : public RandomAccessFile {
virtual Status InvalidateCache(size_t offset, size_t length) override {
return Status::OK();
}

virtual size_t GetUniqueId(char* id, size_t max_size) const override {
return GetUniqueIdFromFile(hFile_, id, max_size);
}
};

// This is a sequential write class. It has been mimicked (as others) after
Expand Down Expand Up @@ -1088,6 +1127,10 @@ class WinWritableFile : public WritableFile {
}
return status;
}

virtual size_t GetUniqueId(char* id, size_t max_size) const override {
return GetUniqueIdFromFile(hFile_, id, max_size);
}
};

class WinDirectory : public Directory {
Expand Down

0 comments on commit bac3be7

Please sign in to comment.