mirror of
https://github.com/rqlite/rqlite.git
synced 2026-01-24 20:06:23 +00:00
Kkostial/minor refactorings
This commit is contained in:
@@ -106,7 +106,7 @@ func (d *Downloader) Do(ctx context.Context, w io.Writer, timeout time.Duration)
|
||||
if err == nil {
|
||||
stats.Add(numDownloadsOK, 1)
|
||||
if cw != nil {
|
||||
stats.Add(numDownloadBytes, int64(cw.count))
|
||||
stats.Add(numDownloadBytes, cw.count)
|
||||
}
|
||||
} else {
|
||||
stats.Add(numDownloadsFail, 1)
|
||||
|
||||
@@ -106,7 +106,7 @@ type Database interface {
|
||||
// Backup writes a backup of the database to the writer.
|
||||
Backup(br *command.BackupRequest, dst io.Writer) error
|
||||
|
||||
// Loads an entire SQLite file into the database
|
||||
// Load an entire SQLite file into the database
|
||||
Load(lr *command.LoadRequest) error
|
||||
}
|
||||
|
||||
|
||||
@@ -501,7 +501,7 @@ func Test_ServiceJoinNodeForwarded(t *testing.T) {
|
||||
dbF := mustNewMockDatabase()
|
||||
mgrF := mustNewMockManager()
|
||||
sF := New(tnF, dbF, mgrF, cred)
|
||||
if sL == nil {
|
||||
if sF == nil {
|
||||
t.Fatalf("failed to create cluster service for Follower")
|
||||
}
|
||||
mgrF.joinFn = func(jr *command.JoinRequest) error {
|
||||
|
||||
@@ -102,7 +102,8 @@ func queryWithClient(ctx *cli.Context, client *cl.Client, timer, blobArray bool,
|
||||
// If the error is HostChangedError, it should be propagated back to the caller to handle
|
||||
// accordingly (change prompt display), but we should still assume that the request succeeded on some
|
||||
// host and not treat it as an error.
|
||||
innerErr, ok := err.(*cl.HostChangedError)
|
||||
var innerErr *cl.HostChangedError
|
||||
ok := errors.As(err, &innerErr)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
consul "github.com/rqlite/rqlite-disco-clients/consul"
|
||||
"github.com/rqlite/rqlite-disco-clients/consul"
|
||||
"github.com/rqlite/rqlite-disco-clients/dns"
|
||||
"github.com/rqlite/rqlite-disco-clients/dnssrv"
|
||||
etcd "github.com/rqlite/rqlite-disco-clients/etcd"
|
||||
"github.com/rqlite/rqlite-disco-clients/etcd"
|
||||
"github.com/rqlite/rqlite/v9/auth"
|
||||
"github.com/rqlite/rqlite/v9/auto/backup"
|
||||
"github.com/rqlite/rqlite/v9/auto/restore"
|
||||
|
||||
@@ -124,7 +124,7 @@ func (d *DechunkerManager) Delete(id string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Closes closes the DechunkerManager and all Dechunkers it manages.
|
||||
// Close closes the DechunkerManager and all Dechunkers it manages.
|
||||
func (d *DechunkerManager) Close() {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
@@ -218,7 +218,7 @@ func (s *SwappableDB) RegisterPreUpdateHook(hook PreUpdateHookCallback, tblRe *r
|
||||
return s.db.RegisterPreUpdateHook(hook, tblRe, rowIDsOnly)
|
||||
}
|
||||
|
||||
// RegisterPreUpdateHook registers a commit hook on the underlying database.
|
||||
// RegisterCommitHook registers a commit hook on the underlying database.
|
||||
func (s *SwappableDB) RegisterCommitHook(hook CommitHookCallback) error {
|
||||
s.dbMu.RLock()
|
||||
defer s.dbMu.RUnlock()
|
||||
|
||||
@@ -104,7 +104,7 @@ func (qp QueryParams) BlobArray() bool {
|
||||
return qp.HasKey("blob_array")
|
||||
}
|
||||
|
||||
// NoRewrite returns true if the query parameters request no rewriting of queries.
|
||||
// NoRewriteRandom returns true if the query parameters request no rewriting of queries.
|
||||
func (qp QueryParams) NoRewriteRandom() bool {
|
||||
return qp.HasKey("norwrandom")
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func Test_SingleParameterizedRequestNull(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_SingleNamedParameterizedRequest(t *testing.T) {
|
||||
if _, err := strconv.ParseInt(string("1.23"), 10, 64); err == nil {
|
||||
if _, err := strconv.ParseInt("1.23", 10, 64); err == nil {
|
||||
// Just be sure that strconv.ParseInt fails on float, since
|
||||
// the internal implementation of ParseRequest relies on it.
|
||||
t.Fatal("strconv.ParseInt should fail on float")
|
||||
|
||||
@@ -1063,7 +1063,7 @@ func Test_FormRedirectParam(t *testing.T) {
|
||||
t.Fatalf("failed to form redirect: %s", err.Error())
|
||||
}
|
||||
|
||||
if exp, got := "http://foo:4001/db/query?x=y", rd; rd != got {
|
||||
if exp, got := "http://foo:4001/db/query?x=y", rd; exp != got {
|
||||
t.Fatalf("incorrect redirect, exp: %s, got: %s", exp, got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +120,9 @@ func (cm *CountingMonitor) runOnce() {
|
||||
cm.loggerFn(cm.ctr.Count())
|
||||
}
|
||||
|
||||
func (m *CountingMonitor) StopAndWait() {
|
||||
m.once.Do(func() {
|
||||
m.cancel()
|
||||
<-m.doneCh
|
||||
func (cm *CountingMonitor) StopAndWait() {
|
||||
cm.once.Do(func() {
|
||||
cm.cancel()
|
||||
<-cm.doneCh
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func IntN(n, l int) []int {
|
||||
return nums
|
||||
}
|
||||
|
||||
// String returns a random string of n characters long.
|
||||
// StringN returns a random string of n characters long.
|
||||
func StringN(n int) string {
|
||||
var output strings.Builder
|
||||
output.Grow(n)
|
||||
|
||||
@@ -24,7 +24,7 @@ func Test_GenerateCACert(t *testing.T) {
|
||||
}
|
||||
|
||||
key, _ := pem.Decode(keyPEM)
|
||||
if err != nil {
|
||||
if key == nil {
|
||||
t.Fatal("failed to decode key")
|
||||
}
|
||||
|
||||
|
||||
@@ -594,17 +594,19 @@ func (c *cmpSnapshotMeta) Less(other *cmpSnapshotMeta) bool {
|
||||
|
||||
type snapMetaSlice []*raft.SnapshotMeta
|
||||
|
||||
// Implement the sort interface for []*fileSnapshotMeta.
|
||||
// Len implements the sort interface for snapMetaSlice.
|
||||
func (s snapMetaSlice) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
// Less implements the sort interface for snapMetaSlice.
|
||||
func (s snapMetaSlice) Less(i, j int) bool {
|
||||
si := (*cmpSnapshotMeta)(s[i])
|
||||
sj := (*cmpSnapshotMeta)(s[j])
|
||||
return si.Less(sj)
|
||||
}
|
||||
|
||||
// Swap implements the sort interface for snapMetaSlice.
|
||||
func (s snapMetaSlice) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const (
|
||||
v7StateFile = "state.bin"
|
||||
)
|
||||
|
||||
// Upgrade writes a copy of the 7.x-format Snapshot directory at 'old' to a
|
||||
// Upgrade7To8 writes a copy of the 7.x-format Snapshot directory at 'old' to a
|
||||
// 8.x-format new Snapshot directory at 'new'. If the upgrade is successful,
|
||||
// the 'old' directory is removed before the function returns.
|
||||
func Upgrade7To8(old, new string, logger *log.Logger) (retErr error) {
|
||||
|
||||
@@ -14,7 +14,7 @@ func Test_Decompressor(t *testing.T) {
|
||||
testData := []byte("This is a test string, xxxxx -- xxxxxx -- test should compress")
|
||||
var buf bytes.Buffer
|
||||
gzw := gzip.NewWriter(&buf)
|
||||
gzw.Write([]byte(testData))
|
||||
gzw.Write(testData)
|
||||
gzw.Close()
|
||||
|
||||
// Decompress the data
|
||||
@@ -26,7 +26,7 @@ func Test_Decompressor(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify the decompressed data matches original data
|
||||
if !bytes.Equal(decompressedBuffer.Bytes(), []byte(testData)) {
|
||||
if !bytes.Equal(decompressedBuffer.Bytes(), testData) {
|
||||
t.Fatalf("decompressed data does not match original")
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func Test_Decompressor_EndToEnd(t *testing.T) {
|
||||
t.Fatalf("failed to decompress: %v", err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(dstBuf.Bytes(), []byte(testData)) {
|
||||
if !bytes.Equal(dstBuf.Bytes(), testData) {
|
||||
t.Fatalf("decompressed data does not match original")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (p *Provider) LastIndex() (uint64, error) {
|
||||
return p.str.DBAppliedIndex(), nil
|
||||
}
|
||||
|
||||
// Provider writes the SQLite database to the given path. If path exists,
|
||||
// Provide writes the SQLite database to the given path. If path exists,
|
||||
// it will be overwritten.
|
||||
func (p *Provider) Provide(w io.Writer) (retErr error) {
|
||||
stats.Add(numProviderProvides, 1)
|
||||
|
||||
@@ -121,7 +121,7 @@ func Test_Server_Sort(t *testing.T) {
|
||||
}
|
||||
expectedOrder := []string{"1", "2", "3"}
|
||||
|
||||
sort.Sort(Servers(servers))
|
||||
sort.Sort(servers)
|
||||
|
||||
for i, server := range servers {
|
||||
if server.ID != expectedOrder[i] {
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
"github.com/rqlite/rqlite/v9/command/proto"
|
||||
sql "github.com/rqlite/rqlite/v9/db"
|
||||
"github.com/rqlite/rqlite/v9/db/humanize"
|
||||
wal "github.com/rqlite/rqlite/v9/db/wal"
|
||||
"github.com/rqlite/rqlite/v9/db/wal"
|
||||
"github.com/rqlite/rqlite/v9/internal/progress"
|
||||
"github.com/rqlite/rqlite/v9/internal/random"
|
||||
"github.com/rqlite/rqlite/v9/internal/rsum"
|
||||
@@ -94,7 +94,7 @@ var (
|
||||
// ErrCDCEnabled is returned when CDC is already enabled.
|
||||
ErrCDCEnabled = errors.New("CDC already enabled")
|
||||
|
||||
// ErrInvalidVacuumFormat is returned when the requested backup format is not
|
||||
// ErrInvalidVacuum is returned when the requested backup format is not
|
||||
// compatible with vacuum.
|
||||
ErrInvalidVacuum = errors.New("invalid vacuum")
|
||||
|
||||
@@ -996,7 +996,8 @@ func (s *Store) HasLeader() bool {
|
||||
if !s.open.Is() {
|
||||
return false
|
||||
}
|
||||
return s.raft.Leader() != ""
|
||||
leader, _ := s.raft.LeaderWithID()
|
||||
return leader != ""
|
||||
}
|
||||
|
||||
// IsVoter returns true if the current node is a voter in the cluster. If there
|
||||
@@ -1147,7 +1148,7 @@ func (s *Store) Followers() ([]*Server, error) {
|
||||
|
||||
followers := make([]*Server, 0, len(servers)-1)
|
||||
for i := range servers {
|
||||
if servers[i].ID != raft.ServerID(id) && servers[i].Suffrage == raft.Voter {
|
||||
if servers[i].ID != id && servers[i].Suffrage == raft.Voter {
|
||||
followers = append(followers, &Server{
|
||||
ID: string(servers[i].ID),
|
||||
Addr: string(servers[i].Address),
|
||||
@@ -1770,7 +1771,7 @@ func (s *Store) Backup(br *proto.BackupRequest, dst io.Writer) (retErr error) {
|
||||
return ErrInvalidBackupFormat
|
||||
}
|
||||
|
||||
// Loads an entire SQLite file into the database, sending the request
|
||||
// Load loads an entire SQLite file into the database, sending the request
|
||||
// through the Raft log.
|
||||
func (s *Store) Load(lr *proto.LoadRequest) error {
|
||||
if !s.open.Is() {
|
||||
|
||||
@@ -142,7 +142,6 @@ func Test_StoreCDC_Events_Single(t *testing.T) {
|
||||
}
|
||||
if ev.NewRow.Values[1].GetS() != "fiona" {
|
||||
t.Fatalf("expected new row name value to be 'fiona', got %s", ev.NewRow.Values[1].GetS())
|
||||
break
|
||||
}
|
||||
case <-timeout:
|
||||
t.Fatalf("timeout waiting for CDC INSERT event for table 'foo'")
|
||||
|
||||
@@ -111,7 +111,7 @@ func (n *Node) Execute(stmt string) (string, error) {
|
||||
return n.ExecuteMulti([]string{stmt})
|
||||
}
|
||||
|
||||
// Execute executes a single statement against the node, requesting associative
|
||||
// ExecuteAssoc executes a single statement against the node, requesting associative
|
||||
// output.
|
||||
func (n *Node) ExecuteAssoc(stmt string) (string, error) {
|
||||
return n.postExecuteAssoc(stmt, "text/plain")
|
||||
|
||||
Reference in New Issue
Block a user