Skip to content

Commit 708abcd

Browse files
committed
Add gRPC service for wal_history and backend framework
- Implement gRPC service to provide wal_history information - Add extensible backend framework for gRPC services - Add unit tests for wal_history_service_impl - Refactor test base to support backend/service factory injection - Update documentation to reflect gRPC service and backend framework for wal_history
1 parent 524bcd7 commit 708abcd

25 files changed

Lines changed: 1649 additions & 83 deletions

docs/internal/wal_sync_impl_design.md

Lines changed: 802 additions & 0 deletions
Large diffs are not rendered by default.

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ file(GLOB SOURCES
33
"limestone/replication/*.cpp"
44
"limestone/partitioned_cursor/*.cpp"
55
"limestone/grpc/service/*.cpp"
6+
"limestone/grpc/backend/*.cpp"
67
"limestone/grpc/client/*.cpp"
78
"limestone/wal_sync/*.cpp"
89
)

src/limestone/grpc/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ This directory contains the gRPC implementation for limestone datastore.
44

55
## Directory Structure
66

7+
78
```
89
src/limestone/grpc/
910
├── README.md # This file (directory overview and conventions)
1011
├── proto/ # Protocol Buffer definitions
1112
├── service/ # gRPC service implementations
13+
├── backend/ # gRPC service backend implementations (service logic backend, abstraction for datastore access, etc.)
1214
└── client/ # gRPC client implementations
1315
```
1416

1517
## Naming Conventions
1618

17-
### C++ Namespaces & Protocol Buffer Package
19+
### C++ Namespaces
1820

1921
- `limestone::grpc::service` - gRPC service implementations
22+
- `limestone::grpc::backend` - gRPC backend implementations
2023
- `limestone::grpc::client` - gRPC client implementations
2124
- `limestone::grpc::proto` - Protocol Buffer generated code
2225

@@ -59,6 +62,22 @@ namespace limestone::grpc::client {
5962
5. **Documentation**: Include English comments for all public interfaces
6063
6. **Testing**: Create corresponding test files for each implementation
6164

65+
66+
## Message Versioning
67+
68+
Some gRPC request/response messages include a `version` field for future compatibility.
69+
The version value to use for each message is defined as a constant in `grpc/message_versions.h`.
70+
Both client and service must check and set the version accordingly.
71+
72+
Example:
73+
74+
```cpp
75+
#include "grpc/message_versions.h"
76+
request.set_version(list_wal_history_message_version);
77+
```
78+
79+
The initial version number for each message is 1.
80+
6281
## Build Integration
6382

6483
The gRPC components are integrated into the main limestone build system through CMake.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "backend_shared_impl.h"
2+
namespace limestone::grpc::backend {
3+
4+
using limestone::internal::wal_history;
5+
6+
7+
backend_shared_impl::backend_shared_impl(const boost::filesystem::path& log_dir)
8+
: log_dir_(log_dir) {}
9+
10+
std::vector<wal_history::record> backend_shared_impl::list_wal_history() {
11+
wal_history wal_history_(log_dir_);
12+
return wal_history_.list();
13+
}
14+
15+
} // namespace limestone::grpc::backend
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include "wal_sync/wal_history.h"
5+
6+
namespace limestone::grpc::backend {
7+
8+
class backend_shared_impl {
9+
public:
10+
explicit backend_shared_impl(const boost::filesystem::path& log_dir);
11+
virtual ~backend_shared_impl() = default;
12+
13+
// Shared logic for listing WAL history
14+
std::vector<limestone::internal::wal_history::record> list_wal_history();
15+
16+
private:
17+
boost::filesystem::path log_dir_;
18+
};
19+
20+
} // namespace limestone::grpc::backend
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
/*
3+
* Copyright 2022-2025 Project Tsurugi.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "grpc_service_backend.h"
18+
#include "inproc_backend.h"
19+
#include "standalone_backend.h"
20+
21+
22+
namespace limestone::grpc::backend {
23+
24+
using limestone::api::datastore;
25+
26+
std::unique_ptr<grpc_service_backend> grpc_service_backend::create_inproc(datastore& store, const boost::filesystem::path& log_dir) {
27+
return std::make_unique<inproc_backend>(store, log_dir);
28+
}
29+
30+
std::unique_ptr<grpc_service_backend> grpc_service_backend::create_standalone(const boost::filesystem::path& log_dir) {
31+
return std::make_unique<standalone_backend>(log_dir);
32+
}
33+
34+
} // namespace limestone::grpc::backend
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2022-2025 Project Tsurugi.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
#include <memory>
18+
#include <string>
19+
#include <boost/filesystem.hpp>
20+
#include "limestone/api/datastore.h"
21+
#include "wal_sync/wal_history.h"
22+
23+
namespace limestone::grpc::backend {
24+
25+
using limestone::internal::wal_history;
26+
27+
// Pure interface for gRPC backends.
28+
// Implementations: inproc_backend, standalone_backend.
29+
class grpc_service_backend {
30+
public:
31+
virtual ~grpc_service_backend() = default;
32+
33+
// Factory helpers (unchanged)
34+
[[nodiscard]] static std::unique_ptr<grpc_service_backend> create_inproc(limestone::api::datastore& store, const boost::filesystem::path& log_dir);
35+
[[nodiscard]] static std::unique_ptr<grpc_service_backend> create_standalone(const boost::filesystem::path& log_dir);
36+
37+
// Returns the list of WAL history records.
38+
[[nodiscard]] virtual std::vector<wal_history::record> list_wal_history() = 0;
39+
40+
// Returns the log directory path (for debugging purposes)
41+
[[nodiscard]] virtual boost::filesystem::path get_log_dir() const noexcept = 0;
42+
protected:
43+
grpc_service_backend() = default;
44+
};
45+
46+
} // namespace limestone::grpc::backend
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2022-2025 Project Tsurugi.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "inproc_backend.h"
17+
18+
namespace limestone::grpc::backend {
19+
20+
21+
inproc_backend::inproc_backend(limestone::api::datastore& ds, const boost::filesystem::path& log_dir)
22+
: datastore_(ds), log_dir_(log_dir), backend_shared_impl_(log_dir)
23+
{
24+
}
25+
26+
std::vector<wal_history::record> inproc_backend::list_wal_history() {
27+
return backend_shared_impl_.list_wal_history();
28+
}
29+
30+
boost::filesystem::path inproc_backend::get_log_dir() const noexcept {
31+
return log_dir_;
32+
}
33+
34+
} // namespace limestone::grpc::backend
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2022-2025 Project Tsurugi.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
18+
#include <vector>
19+
#include "grpc_service_backend.h"
20+
#include "backend_shared_impl.h"
21+
namespace limestone::grpc::backend {
22+
23+
class inproc_backend : public grpc_service_backend {
24+
public:
25+
inproc_backend(limestone::api::datastore& ds, const boost::filesystem::path& log_dir);
26+
~inproc_backend() override = default;
27+
28+
std::vector<wal_history::record> list_wal_history() override;
29+
boost::filesystem::path get_log_dir() const noexcept override;
30+
private:
31+
limestone::api::datastore& datastore_;
32+
boost::filesystem::path log_dir_;
33+
backend_shared_impl backend_shared_impl_;
34+
};
35+
36+
} // namespace limestone::grpc::backend
37+
// Move file to src/limestone/grpc/service/backend/inproc_backend.h
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2022-2025 Project Tsurugi.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "standalone_backend.h"
17+
18+
namespace limestone::grpc::backend {
19+
20+
standalone_backend::standalone_backend(const boost::filesystem::path& log_dir)
21+
: log_dir_(log_dir), backend_shared_impl_(log_dir)
22+
{
23+
}
24+
25+
std::vector<wal_history::record> standalone_backend::list_wal_history() {
26+
return backend_shared_impl_.list_wal_history();
27+
}
28+
29+
boost::filesystem::path standalone_backend::get_log_dir() const noexcept {
30+
return log_dir_;
31+
}
32+
33+
} // namespace limestone::grpc::backend

0 commit comments

Comments
 (0)