Skip to content

Commit

Permalink
Merge pull request cockroachdb#1 from ahrtr/rename_module_20221128
Browse files Browse the repository at this point in the history
Refactoring on raft
  • Loading branch information
ahrtr authored Nov 28, 2022
2 parents 52634f0 + fd26ff4 commit 7032c9a
Show file tree
Hide file tree
Showing 58 changed files with 446 additions and 93 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '20 14 * * 5'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
12 changes: 12 additions & 0 deletions .github/workflows/govuln.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Go Vulnerability Checker
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.19.3"
- run: date
- run: go install golang.org/x/vuln/cmd/govulncheck@latest && govulncheck ./...
19 changes: 19 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Static Analysis
on: [push, pull_request]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.19.3"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.49.0
- name: protoc
uses: arduino/setup-protoc@v1
with:
version: '3.14.0'
- run: make verify
13 changes: 13 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Static Analysis
on: [push, pull_request]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.19.3"
# TODO(ahrtr): add test matrix for different platform and ARCH
- run: make test

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
41 changes: 41 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
run:
timeout: 30m
skip-files:
- "^zz_generated.*"

issues:
max-same-issues: 0
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# exclude ineffassing linter for generated files for conversion
- path: conversion\.go
linters:
- ineffassign

linters:
disable-all: true
enable: # please keep this alphabetized
# Don't use soon to deprecated[1] linters that lead to false
# https://github.com/golangci/golangci-lint/issues/1841
# - deadcode
# - structcheck
# - varcheck
- goimports
- ineffassign
- revive
- staticcheck
- stylecheck
- unused
- unconvert # Remove unnecessary type conversions

linters-settings: # please keep this alphabetized
goimports:
local-prefixes: go.etcd.io # Put imports beginning with prefix after 3rd-party packages.
staticcheck:
checks:
- "all"
- "-SA1019" # TODO(fix) Using a deprecated function, variable, constant or field
- "-SA2002" # TODO(fix) Called testing.T.FailNow or SkipNow in a goroutine, which isn’t allowed
stylecheck:
checks:
- "ST1019" # Importing the same package multiple times.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

.PHONY: verify
verify: verify-gofmt verify-dep verify-lint verify-mod-tidy

.PHONY: verify-gofmt
verify-gofmt:
PASSES="gofmt" ./scripts/test.sh

.PHONY: verify-dep
verify-dep:
PASSES="dep" ./scripts/test.sh

.PHONY: verify-lint
verify-lint:
golangci-lint run

.PHONY: verify-mod-tidy
verify-mod-tidy:
PASSES="mod_tidy" ./scripts/test.sh


.PHONY: test
test:
go test ./...

25 changes: 9 additions & 16 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Please keep the list sorted.

approvers:
- heyitsanthony
- philips
- fanminshi
- gyuho
- ahrtr
- hexfusion
- mitake
- jpbetz
- xiang90
- bdarnell
- ptabor
- serathius
- spzala
- tbg

reviewers:
- heyitsanthony
- philips
- fanminshi
- gyuho
- mitake
- jpbetz
- xiang90
- bdarnell
- tschottdorf
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ This approach introduces a problem when removing a member from a two-member clus

## Go docs

More detailed development documentation can be found in go docs: https://pkg.go.dev/go.etcd.io/etcd/raft/v3.
More detailed development documentation can be found in go docs: https://pkg.go.dev/go.etcd.io/raft/v3.
2 changes: 1 addition & 1 deletion bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package raft
import (
"errors"

pb "go.etcd.io/etcd/raft/v3/raftpb"
pb "go.etcd.io/raft/v3/raftpb"
)

// Bootstrap initializes the RawNode for first use by appending configuration
Expand Down
6 changes: 3 additions & 3 deletions confchange/confchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"fmt"
"strings"

"go.etcd.io/etcd/raft/v3/quorum"
pb "go.etcd.io/etcd/raft/v3/raftpb"
"go.etcd.io/etcd/raft/v3/tracker"
"go.etcd.io/raft/v3/quorum"
pb "go.etcd.io/raft/v3/raftpb"
"go.etcd.io/raft/v3/tracker"
)

// Changer facilitates configuration changes. It exposes methods to handle
Expand Down
4 changes: 2 additions & 2 deletions confchange/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"testing"

"github.com/cockroachdb/datadriven"
pb "go.etcd.io/etcd/raft/v3/raftpb"
"go.etcd.io/etcd/raft/v3/tracker"
pb "go.etcd.io/raft/v3/raftpb"
"go.etcd.io/raft/v3/tracker"
)

func TestConfChangeDataDriven(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions confchange/quick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"testing"
"testing/quick"

pb "go.etcd.io/etcd/raft/v3/raftpb"
"go.etcd.io/etcd/raft/v3/tracker"
pb "go.etcd.io/raft/v3/raftpb"
"go.etcd.io/raft/v3/tracker"
)

// TestConfChangeQuick uses quickcheck to verify that simple and joint config
Expand Down
4 changes: 2 additions & 2 deletions confchange/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package confchange

import (
pb "go.etcd.io/etcd/raft/v3/raftpb"
"go.etcd.io/etcd/raft/v3/tracker"
pb "go.etcd.io/raft/v3/raftpb"
"go.etcd.io/raft/v3/tracker"
)

// toConfChangeSingle translates a conf state into 1) a slice of operations creating
Expand Down
4 changes: 2 additions & 2 deletions confchange/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"testing"
"testing/quick"

pb "go.etcd.io/etcd/raft/v3/raftpb"
"go.etcd.io/etcd/raft/v3/tracker"
pb "go.etcd.io/raft/v3/raftpb"
"go.etcd.io/raft/v3/tracker"
)

type rndConfChange pb.ConfState
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package raft

import (
pb "go.etcd.io/etcd/raft/v3/raftpb"
pb "go.etcd.io/raft/v3/raftpb"
)

func applyToStore(ents []pb.Entry) {}
Expand Down
12 changes: 1 addition & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module go.etcd.io/etcd/raft/v3
module go.etcd.io/raft/v3

go 1.19

Expand All @@ -22,13 +22,3 @@ require (
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// Bad imports are sometimes causing attempts to pull that code.
// This makes the error more explicit.
replace go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY

replace go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY

replace go.etcd.io/etcd/client/pkg/v3 => ./FORBIDDEN_DEPENDENCY

replace go.etcd.io/etcd/api/v3 => ./FORBIDDEN_DEPENDENCY
2 changes: 1 addition & 1 deletion interaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"testing"

"github.com/cockroachdb/datadriven"
"go.etcd.io/etcd/raft/v3/rafttest"
"go.etcd.io/raft/v3/rafttest"
)

func TestInteraction(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"log"

pb "go.etcd.io/etcd/raft/v3/raftpb"
pb "go.etcd.io/raft/v3/raftpb"
)

type raftLog struct {
Expand Down
2 changes: 1 addition & 1 deletion log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/stretchr/testify/require"

pb "go.etcd.io/etcd/raft/v3/raftpb"
pb "go.etcd.io/raft/v3/raftpb"
)

func TestFindConflict(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion log_unstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package raft

import pb "go.etcd.io/etcd/raft/v3/raftpb"
import pb "go.etcd.io/raft/v3/raftpb"

// unstable.entries[i] has raft log position i+unstable.offset.
// Note that unstable.offset may be less than the highest log
Expand Down
2 changes: 1 addition & 1 deletion log_unstable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
pb "go.etcd.io/etcd/raft/v3/raftpb"
pb "go.etcd.io/raft/v3/raftpb"
)

func TestUnstableMaybeFirstIndex(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"errors"

pb "go.etcd.io/etcd/raft/v3/raftpb"
pb "go.etcd.io/raft/v3/raftpb"
)

type SnapshotStatus int
Expand Down
2 changes: 1 addition & 1 deletion node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"testing"
"time"

"go.etcd.io/etcd/raft/v3/raftpb"
"go.etcd.io/raft/v3/raftpb"
)

// readyWithTimeout selects from n.Ready() with a 1-second timeout. It
Expand Down
8 changes: 4 additions & 4 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"sync"
"time"

"go.etcd.io/etcd/raft/v3/confchange"
"go.etcd.io/etcd/raft/v3/quorum"
pb "go.etcd.io/etcd/raft/v3/raftpb"
"go.etcd.io/etcd/raft/v3/tracker"
"go.etcd.io/raft/v3/confchange"
"go.etcd.io/raft/v3/quorum"
pb "go.etcd.io/raft/v3/raftpb"
"go.etcd.io/raft/v3/tracker"
)

// None is a placeholder node ID used when there is no leader.
Expand Down
Loading

0 comments on commit 7032c9a

Please sign in to comment.