|
|
@ -74,6 +74,10 @@ ThreadStatusUpdater* CreateThreadStatusUpdater() { |
|
|
|
return new ThreadStatusUpdater(); |
|
|
|
return new ThreadStatusUpdater(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline mode_t GetDBFileMode(bool allow_non_owner_access) { |
|
|
|
|
|
|
|
return allow_non_owner_access ? 0644 : 0600; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// list of pathnames that are locked
|
|
|
|
// list of pathnames that are locked
|
|
|
|
static std::set<std::string> lockedFiles; |
|
|
|
static std::set<std::string> lockedFiles; |
|
|
|
static port::Mutex mutex_lockedFiles; |
|
|
|
static port::Mutex mutex_lockedFiles; |
|
|
@ -167,7 +171,7 @@ class PosixEnv : public Env { |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
fd = open(fname.c_str(), flags, 0644); |
|
|
|
fd = open(fname.c_str(), flags, GetDBFileMode(allow_non_owner_access_)); |
|
|
|
} while (fd < 0 && errno == EINTR); |
|
|
|
} while (fd < 0 && errno == EINTR); |
|
|
|
if (fd < 0) { |
|
|
|
if (fd < 0) { |
|
|
|
return IOError("While opening a file for sequentially reading", fname, |
|
|
|
return IOError("While opening a file for sequentially reading", fname, |
|
|
@ -217,7 +221,7 @@ class PosixEnv : public Env { |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
fd = open(fname.c_str(), flags, 0644); |
|
|
|
fd = open(fname.c_str(), flags, GetDBFileMode(allow_non_owner_access_)); |
|
|
|
} while (fd < 0 && errno == EINTR); |
|
|
|
} while (fd < 0 && errno == EINTR); |
|
|
|
if (fd < 0) { |
|
|
|
if (fd < 0) { |
|
|
|
return IOError("While open a file for random read", fname, errno); |
|
|
|
return IOError("While open a file for random read", fname, errno); |
|
|
@ -288,7 +292,7 @@ class PosixEnv : public Env { |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
fd = open(fname.c_str(), flags, 0644); |
|
|
|
fd = open(fname.c_str(), flags, GetDBFileMode(allow_non_owner_access_)); |
|
|
|
} while (fd < 0 && errno == EINTR); |
|
|
|
} while (fd < 0 && errno == EINTR); |
|
|
|
|
|
|
|
|
|
|
|
if (fd < 0) { |
|
|
|
if (fd < 0) { |
|
|
@ -376,7 +380,8 @@ class PosixEnv : public Env { |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
fd = open(old_fname.c_str(), flags, 0644); |
|
|
|
fd = open(old_fname.c_str(), flags, |
|
|
|
|
|
|
|
GetDBFileMode(allow_non_owner_access_)); |
|
|
|
} while (fd < 0 && errno == EINTR); |
|
|
|
} while (fd < 0 && errno == EINTR); |
|
|
|
if (fd < 0) { |
|
|
|
if (fd < 0) { |
|
|
|
s = IOError("while reopen file for write", fname, errno); |
|
|
|
s = IOError("while reopen file for write", fname, errno); |
|
|
@ -436,7 +441,8 @@ class PosixEnv : public Env { |
|
|
|
int fd = -1; |
|
|
|
int fd = -1; |
|
|
|
while (fd < 0) { |
|
|
|
while (fd < 0) { |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
IOSTATS_TIMER_GUARD(open_nanos); |
|
|
|
fd = open(fname.c_str(), O_CREAT | O_RDWR, 0644); |
|
|
|
fd = open(fname.c_str(), O_CREAT | O_RDWR, |
|
|
|
|
|
|
|
GetDBFileMode(allow_non_owner_access_)); |
|
|
|
if (fd < 0) { |
|
|
|
if (fd < 0) { |
|
|
|
// Error while opening the file
|
|
|
|
// Error while opening the file
|
|
|
|
if (errno == EINTR) { |
|
|
|
if (errno == EINTR) { |
|
|
@ -789,6 +795,11 @@ class PosixEnv : public Env { |
|
|
|
return thread_pools_[pri].GetBackgroundThreads(); |
|
|
|
return thread_pools_[pri].GetBackgroundThreads(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual Status SetAllowNonOwnerAccess(bool allow_non_owner_access) override { |
|
|
|
|
|
|
|
allow_non_owner_access_ = allow_non_owner_access; |
|
|
|
|
|
|
|
return Status::OK(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Allow increasing the number of worker threads.
|
|
|
|
// Allow increasing the number of worker threads.
|
|
|
|
virtual void IncBackgroundThreadsIfNeeded(int num, Priority pri) override { |
|
|
|
virtual void IncBackgroundThreadsIfNeeded(int num, Priority pri) override { |
|
|
|
assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH); |
|
|
|
assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH); |
|
|
@ -888,13 +899,17 @@ class PosixEnv : public Env { |
|
|
|
std::vector<ThreadPoolImpl> thread_pools_; |
|
|
|
std::vector<ThreadPoolImpl> thread_pools_; |
|
|
|
pthread_mutex_t mu_; |
|
|
|
pthread_mutex_t mu_; |
|
|
|
std::vector<pthread_t> threads_to_join_; |
|
|
|
std::vector<pthread_t> threads_to_join_; |
|
|
|
|
|
|
|
// If true, allow non owner read access for db files. Otherwise, non-owner
|
|
|
|
|
|
|
|
// has no access to db files.
|
|
|
|
|
|
|
|
bool allow_non_owner_access_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
PosixEnv::PosixEnv() |
|
|
|
PosixEnv::PosixEnv() |
|
|
|
: checkedDiskForMmap_(false), |
|
|
|
: checkedDiskForMmap_(false), |
|
|
|
forceMmapOff_(false), |
|
|
|
forceMmapOff_(false), |
|
|
|
page_size_(getpagesize()), |
|
|
|
page_size_(getpagesize()), |
|
|
|
thread_pools_(Priority::TOTAL) { |
|
|
|
thread_pools_(Priority::TOTAL), |
|
|
|
|
|
|
|
allow_non_owner_access_(true) { |
|
|
|
ThreadPoolImpl::PthreadCall("mutex_init", pthread_mutex_init(&mu_, nullptr)); |
|
|
|
ThreadPoolImpl::PthreadCall("mutex_init", pthread_mutex_init(&mu_, nullptr)); |
|
|
|
for (int pool_id = 0; pool_id < Env::Priority::TOTAL; ++pool_id) { |
|
|
|
for (int pool_id = 0; pool_id < Env::Priority::TOTAL; ++pool_id) { |
|
|
|
thread_pools_[pool_id].SetThreadPriority( |
|
|
|
thread_pools_[pool_id].SetThreadPriority( |
|
|
|