Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
path: deps/3rd/usr/local
- name: BuildDebug
shell: bash
run: bash build.sh debug -DCONCURRENCY=ON -DENABLE_COVERAGE=ON -DWITH_BENCHMARK=ON -DWITH_MEMTRACER=ON -DWITH_UNIT_TESTS=ON --make -j4
run: bash build.sh debug -DENABLE_COVERAGE=ON -DWITH_BENCHMARK=ON -DWITH_MEMTRACER=ON -DWITH_UNIT_TESTS=ON --make -j4

- name: Test
shell: bash
Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
path: deps/3rd/usr/local
- name: BuildRelease
shell: bash
run: bash build.sh release -DCONCURRENCY=ON -DWITH_UNIT_TESTS=ON -DWITH_BENCHMARK=ON -DENABLE_ASAN=OFF -DWITH_MEMTRACER=ON --make -j4
run: bash build.sh release -DWITH_UNIT_TESTS=ON -DWITH_BENCHMARK=ON -DENABLE_ASAN=OFF -DWITH_MEMTRACER=ON --make -j4

- name: Upload release artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -386,4 +386,4 @@ jobs:
export PATH="/opt/homebrew/opt/bison/bin:$PATH"
sudo bash build.sh init
bash build.sh debug -DWITH_MEMTRACER=ON --make -j4
bash build.sh release -DCONCURRENCY=ON -DWITH_UNIT_TESTS=OFF -DWITH_BENCHMARK=ON -DWITH_MEMTRACER=ON --make -j4
bash build.sh release -DWITH_UNIT_TESTS=OFF -DWITH_BENCHMARK=ON -DWITH_MEMTRACER=ON --make -j4
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ OPTION(WITH_BENCHMARK "Compile benchmark" OFF)
OPTION(WITH_MEMTRACER "Compile memtracer" OFF)
OPTION(ENABLE_COVERAGE "Enable unittest coverage" OFF)
OPTION(ENABLE_NOPIE "Enable no pie" OFF)
OPTION(CONCURRENCY "Support concurrency operations" OFF)
OPTION(STATIC_STDLIB "Link std library static or dynamic, such as libgcc, libstdc++, libasan" OFF)
OPTION(USE_SIMD "Use SIMD" OFF)
OPTION(USE_MUSL_LIBC "Use musl libc" OFF)
Expand Down Expand Up @@ -75,12 +74,6 @@ IF(USE_SIMD)
ADD_DEFINITIONS(-DUSE_SIMD)
ENDIF(USE_SIMD)

IF (CONCURRENCY)
MESSAGE(STATUS "CONCURRENCY is ON")
SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -DCONCURRENCY")
ADD_DEFINITIONS(-DCONCURRENCY)
ENDIF (CONCURRENCY)

MESSAGE(STATUS "CMAKE_CXX_COMPILER_ID is " ${CMAKE_CXX_COMPILER_ID})
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND ${STATIC_STDLIB})
ADD_LINK_OPTIONS(-static-libgcc -static-libstdc++)
Expand Down
13 changes: 0 additions & 13 deletions docs/docs/how_to_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ title: 如何运行
```
这会连接到服务端的miniob.sock文件。

**并发模式**

默认情况下,编译出的程序是不支持并发的。如果需要支持并发,需要在编译时增加选项 `-DCONCURRENCY=ON`:
```bash
cmake -DCONCURRENCY=ON ..
```

或者

```bash
bash build.sh -DCONCURRENCY=ON
```

然后使用上面的命令启动服务端程序,就可以支持并发了。

**启动参数介绍**
Expand Down
39 changes: 1 addition & 38 deletions src/common/lang/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,36 +278,26 @@ void DebugMutex::unlock()
////////////////////////////////////////////////////////////////////////////////
void Mutex::lock()
{
#ifdef CONCURRENCY
lock_.lock();
LOG_DEBUG("lock %p, lbt=%s", &lock_, lbt());
#endif
}

bool Mutex::try_lock()
{
#ifdef CONCURRENCY
bool result = lock_.try_lock();
if (result) {
LOG_DEBUG("try lock success %p, lbt=%s", &lock_, lbt());
}
return result;
#else
return true;
#endif
}

void Mutex::unlock()
{
#ifdef CONCURRENCY
LOG_DEBUG("unlock %p, lbt=%s", &lock_, lbt());
lock_.unlock();
#endif
}

////////////////////////////////////////////////////////////////////////////////
#ifdef CONCURRENCY

void SharedMutex::lock()
{
lock_.lock();
Expand Down Expand Up @@ -346,33 +336,7 @@ void SharedMutex::unlock_shared()
lock_.unlock_shared();
}

#else // CONCURRENCY undefined

void SharedMutex::lock() {}
bool SharedMutex::try_lock() { return true; }
void SharedMutex::unlock() // unlock exclusive
{}

void SharedMutex::lock_shared() {}
bool SharedMutex::try_lock_shared() { return true; }
void SharedMutex::unlock_shared() {}

#endif // CONCURRENCY end

////////////////////////////////////////////////////////////////////////////////
#ifndef CONCURRENCY
void RecursiveSharedMutex::lock_shared() {}

bool RecursiveSharedMutex::try_lock_shared() { return true; }

void RecursiveSharedMutex::unlock_shared() {}

void RecursiveSharedMutex::lock() {}

void RecursiveSharedMutex::unlock() {}

#else // ifdef CONCURRENCY

void RecursiveSharedMutex::lock_shared()
{
unique_lock<mutex> lock(mutex_);
Expand Down Expand Up @@ -431,6 +395,5 @@ void RecursiveSharedMutex::unlock()
}
}
}
#endif // CONCURRENCY

} // namespace common
} // namespace common
7 changes: 0 additions & 7 deletions src/common/lang/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ class Mutex final
void unlock();

private:
#ifdef CONCURRENCY
mutex lock_;
#endif
};

class SharedMutex final
Expand All @@ -295,16 +293,13 @@ class SharedMutex final
void unlock_shared();

private:
#ifdef CONCURRENCY
shared_mutex lock_;
#endif
};

/**
* 支持写锁递归加锁的读写锁
* 读锁本身就可以递归加锁。但是某个线程加了读锁后,也不能再加写锁。
* 但是一个线程可以加多次写锁
* 与其它类型的锁一样,在CONCURRENCY编译模式下才会真正的生效
*/
class RecursiveSharedMutex
{
Expand All @@ -320,15 +315,13 @@ class RecursiveSharedMutex
void unlock();

private:
#ifdef CONCURRENCY
mutex mutex_;
condition_variable shared_lock_cv_;
condition_variable exclusive_lock_cv_;
int shared_lock_count_ = 0;
int exclusive_lock_count_ = 0;
thread::id recursive_owner_;
int recursive_count_ = 0; // 表示当前线程加写锁加了多少次
#endif // CONCURRENCY
};

} // namespace common
2 changes: 1 addition & 1 deletion src/observer/storage/record/record_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class RecordFileHandler
DiskBufferPool *disk_buffer_pool_ = nullptr;
LogHandler *log_handler_ = nullptr; ///< 记录日志的处理器
unordered_set<PageNum> free_pages_; ///< 没有填充满的页面集合
common::Mutex lock_; ///< 当编译时增加-DCONCURRENCY=ON 选项时,才会真正的支持并发
common::Mutex lock_; ///< 记录管理器的锁
StorageFormat storage_format_;
TableMeta *table_meta_;
LobFileHandler *lob_handler_ = nullptr;
Expand Down