Skip to content

Commit 49860b6

Browse files
authored
Merge branch 'main' into feature/fix-create-node
2 parents 464f43a + 23b4e1d commit 49860b6

31 files changed

+2380
-102
lines changed

.github/workflows/docker-image.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
name: Docker Image CI
2+
permissions:
3+
contents: read
4+
packages: write
25

36
on:
47
push:
@@ -14,7 +17,7 @@ jobs:
1417
runs-on: ubuntu-latest
1518

1619
steps:
17-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v6
1821
with:
1922
submodules: true
2023
# - name: Set up QEMU

.github/workflows/go-mod-fix.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ on:
66

77
jobs:
88
go-mod-fix:
9+
permissions:
10+
contents: write
911
runs-on: ubuntu-latest
1012
steps:
1113
- name: checkout
12-
uses: actions/checkout@v4
14+
uses: actions/checkout@v6
1315
with:
1416
fetch-depth: 2
1517
- name: fix

.github/workflows/go-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ concurrency:
88
# cancel-in-progress: true
99

1010
name: Test
11+
permissions:
12+
contents: read
1113
jobs:
1214
test:
1315
strategy:
1416
matrix:
1517
os: [ [ubuntu-latest] ]
1618
runs-on: ${{ matrix.os }}
1719
steps:
18-
- uses: actions/checkout@v4
19-
- uses: actions/setup-go@v5
20+
- uses: actions/checkout@v6
21+
- uses: actions/setup-go@v6
2022
with:
2123
go-version-file: 'go.mod'
2224
- run: go test -race ./...

.github/workflows/golangci-lint.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ concurrency:
1111
jobs:
1212
golangci-lint:
1313
name: golangci-lint
14+
permissions:
15+
contents: read
16+
pull-requests: write
1417
runs-on: ubuntu-latest
1518
steps:
1619
- name: Check out code into the Go module directory
17-
uses: actions/checkout@v4
20+
uses: actions/checkout@v6
1821
- name: golangci-lint
1922
uses: reviewdog/action-golangci-lint@v2
2023
with:

.github/workflows/jepsen-test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on: [ push ]
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}-jepsen-test
5+
6+
name: Jepsen Test
7+
permissions:
8+
contents: read
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
env:
13+
RUN_JEPSEN: 'true'
14+
steps:
15+
- uses: actions/checkout@v6
16+
- uses: actions/setup-java@v5
17+
with:
18+
distribution: temurin
19+
java-version: '21'
20+
- name: Install Leiningen
21+
run: |
22+
curl -L https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > ~/lein
23+
chmod +x ~/lein
24+
~/lein version
25+
- name: Run Jepsen tests
26+
if: env.RUN_JEPSEN == 'true'
27+
working-directory: jepsen
28+
run: ~/lein test

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@
1919

2020
# Go workspace file
2121
go.work
22+
23+
# Built binary
24+
/elastickv
25+
26+
# Clojure/Leiningen build artifacts
27+
jepsen/target/
28+
jepsen/.lein-*
29+
jepsen/.nrepl-port

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ quit
7171

7272
### Development
7373

74+
### Running Jepsen tests
75+
76+
Jepsen tests live in `jepsen/`. Install Leiningen and run tests locally:
77+
78+
```bash
79+
curl -L https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > ~/lein
80+
chmod +x ~/lein
81+
(cd jepsen && ~/lein test)
82+
```
83+
84+
These Jepsen tests execute concurrent read and write operations while a nemesis
85+
injects random network partitions. Jepsen's linearizability checker verifies the
86+
history.
87+
88+
7489

7590
### Setup pre-commit hooks
7691
```bash

adapter/distribution_server.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package adapter
2+
3+
import (
4+
"context"
5+
6+
"github.com/bootjp/elastickv/distribution"
7+
pb "github.com/bootjp/elastickv/proto"
8+
)
9+
10+
// DistributionServer serves distribution related gRPC APIs.
11+
type DistributionServer struct {
12+
engine *distribution.Engine
13+
pb.UnimplementedDistributionServer
14+
}
15+
16+
// NewDistributionServer creates a new server.
17+
func NewDistributionServer(e *distribution.Engine) *DistributionServer {
18+
return &DistributionServer{engine: e}
19+
}
20+
21+
// UpdateRoute allows updating route information.
22+
func (s *DistributionServer) UpdateRoute(start, end []byte, group uint64) {
23+
s.engine.UpdateRoute(start, end, group)
24+
}
25+
26+
// GetRoute returns route for a key.
27+
func (s *DistributionServer) GetRoute(ctx context.Context, req *pb.GetRouteRequest) (*pb.GetRouteResponse, error) {
28+
r, ok := s.engine.GetRoute(req.Key)
29+
if !ok {
30+
return &pb.GetRouteResponse{}, nil
31+
}
32+
return &pb.GetRouteResponse{
33+
Start: r.Start,
34+
End: r.End,
35+
RaftGroupId: r.GroupID,
36+
}, nil
37+
}
38+
39+
// GetTimestamp returns monotonically increasing timestamp.
40+
func (s *DistributionServer) GetTimestamp(ctx context.Context, req *pb.GetTimestampRequest) (*pb.GetTimestampResponse, error) {
41+
ts := s.engine.NextTimestamp()
42+
return &pb.GetTimestampResponse{Timestamp: ts}, nil
43+
}

0 commit comments

Comments
 (0)