diff --git a/changelog/11269.txt b/changelog/11269.txt new file mode 100644 index 000000000..d732eaf3a --- /dev/null +++ b/changelog/11269.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +storage/raft: Switch to shared raft-boltdb library and add boltdb metrics +``` diff --git a/go.mod b/go.mod index 721a74288..23c6d74f2 100644 --- a/go.mod +++ b/go.mod @@ -63,7 +63,7 @@ require ( github.com/hashicorp/go-hclog v0.15.0 github.com/hashicorp/go-kms-wrapping v0.5.16 github.com/hashicorp/go-memdb v1.0.2 - github.com/hashicorp/go-msgpack v0.5.5 + github.com/hashicorp/go-msgpack v0.5.5 // indirect github.com/hashicorp/go-multierror v1.1.0 github.com/hashicorp/go-raftchunking v0.6.3-0.20191002164813-7e9e8525653a github.com/hashicorp/go-retryablehttp v0.6.7 @@ -76,6 +76,7 @@ require ( github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d github.com/hashicorp/raft v1.2.0 github.com/hashicorp/raft-autopilot v0.1.2 + github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210421194847-a7e34179d62c github.com/hashicorp/raft-snapshot v1.0.3 github.com/hashicorp/serf v0.9.5 // indirect github.com/hashicorp/vault-plugin-auth-alicloud v0.8.0 diff --git a/go.sum b/go.sum index 1385fa0bd..5125b3bae 100644 --- a/go.sum +++ b/go.sum @@ -650,12 +650,18 @@ github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d h1:BXqsASWhyiAiEVm6FcltF0dg8XvoookQwmpHn8lstu8= github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d/go.mod h1:WKCL+tLVhN1D+APwH3JiTRZoxcdwRk86bWu1LVCUPaE= github.com/hashicorp/raft v1.0.1/go.mod h1:DVSAWItjLjTOkVbSpWQ0j0kUADIvDaCtBxIcbNAQLkI= +github.com/hashicorp/raft v1.1.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= github.com/hashicorp/raft v1.1.2-0.20191002163536-9c6bd3e3eb17/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8= github.com/hashicorp/raft v1.2.0 h1:mHzHIrF0S91d3A7RPBvuqkgB4d/7oFJZyvf1Q4m7GA0= github.com/hashicorp/raft v1.2.0/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8= github.com/hashicorp/raft-autopilot v0.1.2 h1:yeqdUjWLjVJkBM+mcVxqwxi+w+aHsb9cEON2dz69OCs= github.com/hashicorp/raft-autopilot v0.1.2/go.mod h1:Af4jZBwaNOI+tXfIqIdbcAnh/UyyqIMj/pOISIfhArw= +github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea h1:xykPFhrBAS2J0VBzVa5e80b5ZtYuNQtgXjN40qBZlD4= github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk= +github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210409134258-03c10cc3d4ea h1:pXD01QLdHmn4Ij82g1vksWbZXwSH6il7Svrm/rdUk18= +github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210409134258-03c10cc3d4ea/go.mod h1:kiPs9g148eLShc2TYagUAyKDnD+dH9U+CQKsXzlY9xo= +github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210421194847-a7e34179d62c h1:oiKun9QlrOz5yQxMZJ3tf1kWtFYuKSJzxzEDxDPevj4= +github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210421194847-a7e34179d62c/go.mod h1:kiPs9g148eLShc2TYagUAyKDnD+dH9U+CQKsXzlY9xo= github.com/hashicorp/raft-snapshot v1.0.3 h1:lTgBBGMFcuKBTwHqWZ4r0TLzNsqo/OByCga/kM6F0uM= github.com/hashicorp/raft-snapshot v1.0.3/go.mod h1:5sL9eUn72lH5DzsFIJ9jaysITbHksSSszImWSOTC8Ic= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= diff --git a/helper/testhelpers/testhelpers.go b/helper/testhelpers/testhelpers.go index 4d2741512..b7a5cea82 100644 --- a/helper/testhelpers/testhelpers.go +++ b/helper/testhelpers/testhelpers.go @@ -12,9 +12,10 @@ import ( "sync/atomic" "time" - "github.com/hashicorp/vault/api" - + "github.com/armon/go-metrics" raftlib "github.com/hashicorp/raft" + "github.com/hashicorp/vault/api" + "github.com/hashicorp/vault/helper/metricsutil" "github.com/hashicorp/vault/helper/namespace" "github.com/hashicorp/vault/helper/xor" "github.com/hashicorp/vault/physical/raft" @@ -658,6 +659,15 @@ func VerifyRaftPeers(t testing.T, client *api.Client, expected map[string]bool) } } +func TestMetricSinkProvider(gaugeInterval time.Duration) func(string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper) { + return func(clusterName string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper) { + inm := metrics.NewInmemSink(1000000*time.Hour, 2000000*time.Hour) + clusterSink := metricsutil.NewClusterMetricSink(clusterName, inm) + clusterSink.GaugeInterval = gaugeInterval + return clusterSink, metricsutil.NewMetricsHelper(inm, false) + } +} + func SysMetricsReq(client *api.Client, cluster *vault.TestCluster, unauth bool) (*SysMetricsJSON, error) { r := client.NewRequest("GET", "/v1/sys/metrics") if !unauth { diff --git a/physical/raft/chunking_test.go b/physical/raft/chunking_test.go index 23b5f8fb0..bdd950b56 100644 --- a/physical/raft/chunking_test.go +++ b/physical/raft/chunking_test.go @@ -12,7 +12,7 @@ import ( raftchunkingtypes "github.com/hashicorp/go-raftchunking/types" uuid "github.com/hashicorp/go-uuid" "github.com/hashicorp/raft" - raftboltdb "github.com/hashicorp/vault/physical/raft/logstore" + "github.com/hashicorp/raft-boltdb/v2" "github.com/hashicorp/vault/sdk/physical" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/physical/raft/fsm.go b/physical/raft/fsm.go index 4c043c817..86cb08279 100644 --- a/physical/raft/fsm.go +++ b/physical/raft/fsm.go @@ -61,7 +61,7 @@ type FSMApplyResponse struct { Success bool } -// FSM is Vault's primary state storage. It writes updates to an bolt db file +// FSM is Vault's primary state storage. It writes updates to a bolt db file // that lives on local disk. FSM implements raft.FSM and physical.Backend // interfaces. type FSM struct { diff --git a/physical/raft/raft.go b/physical/raft/raft.go index b0a086ab1..2a458b4d8 100644 --- a/physical/raft/raft.go +++ b/physical/raft/raft.go @@ -13,12 +13,6 @@ import ( "sync" "time" - "github.com/hashicorp/vault/sdk/helper/consts" - "github.com/hashicorp/vault/sdk/helper/jsonutil" - "github.com/hashicorp/vault/sdk/helper/tlsutil" - "github.com/hashicorp/vault/sdk/logical" - "github.com/hashicorp/vault/sdk/physical" - "github.com/armon/go-metrics" "github.com/golang/protobuf/proto" "github.com/hashicorp/errwrap" @@ -28,10 +22,17 @@ import ( "github.com/hashicorp/go-uuid" "github.com/hashicorp/raft" autopilot "github.com/hashicorp/raft-autopilot" + "github.com/hashicorp/raft-boltdb/v2" snapshot "github.com/hashicorp/raft-snapshot" - raftboltdb "github.com/hashicorp/vault/physical/raft/logstore" + "github.com/hashicorp/vault/helper/metricsutil" + "github.com/hashicorp/vault/sdk/helper/consts" + "github.com/hashicorp/vault/sdk/helper/jsonutil" + "github.com/hashicorp/vault/sdk/helper/tlsutil" + "github.com/hashicorp/vault/sdk/logical" + "github.com/hashicorp/vault/sdk/physical" "github.com/hashicorp/vault/vault/cluster" "github.com/hashicorp/vault/vault/seal" + bolt "go.etcd.io/bbolt" ) // EnvVaultRaftNodeID is used to fetch the Raft node ID from the environment. @@ -477,6 +478,38 @@ func (b *RaftBackend) Close() error { return nil } +func (b *RaftBackend) CollectMetrics(sink *metricsutil.ClusterMetricSink) { + b.l.RLock() + logstoreStats := b.stableStore.(*raftboltdb.BoltStore).Stats() + fsmStats := b.fsm.db.Stats() + b.l.RUnlock() + b.collectMetricsWithStats(logstoreStats, sink, "logstore") + b.collectMetricsWithStats(fsmStats, sink, "fsm") +} + +func (b *RaftBackend) collectMetricsWithStats(stats bolt.Stats, sink *metricsutil.ClusterMetricSink, database string) { + txstats := stats.TxStats + labels := []metricsutil.Label{{"database", database}} + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "freelist", "free_pages"}, float32(stats.FreePageN), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "freelist", "pending_pages"}, float32(stats.PendingPageN), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "freelist", "allocated_bytes"}, float32(stats.FreeAlloc), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "freelist", "used_bytes"}, float32(stats.FreelistInuse), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "transaction", "started_read_transactions"}, float32(stats.TxN), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "transaction", "currently_open_read_transactions"}, float32(stats.OpenTxN), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "page", "count"}, float32(txstats.PageCount), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "page", "bytes_allocated"}, float32(txstats.PageAlloc), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "cursor", "count"}, float32(txstats.CursorCount), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "node", "count"}, float32(txstats.NodeCount), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "node", "dereferences"}, float32(txstats.NodeDeref), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "rebalance", "count"}, float32(txstats.Rebalance), labels) + sink.AddSampleWithLabels([]string{"raft_storage", "bolt", "rebalance", "time"}, float32(txstats.RebalanceTime), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "split", "count"}, float32(txstats.Split), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "spill", "count"}, float32(txstats.Spill), labels) + sink.AddSampleWithLabels([]string{"raft_storage", "bolt", "spill", "time"}, float32(txstats.SpillTime), labels) + sink.SetGaugeWithLabels([]string{"raft_storage", "bolt", "write", "count"}, float32(txstats.Write), labels) + sink.AddSampleWithLabels([]string{"raft_storage", "bolt", "write", "time"}, float32(txstats.WriteTime), labels) +} + // RaftServer has information about a server in the Raft configuration type RaftServer struct { // NodeID is the name of the server diff --git a/vault/core_metrics.go b/vault/core_metrics.go index bb9460c97..6477721ec 100644 --- a/vault/core_metrics.go +++ b/vault/core_metrics.go @@ -10,6 +10,7 @@ import ( "github.com/armon/go-metrics" "github.com/hashicorp/vault/helper/metricsutil" "github.com/hashicorp/vault/helper/namespace" + "github.com/hashicorp/vault/physical/raft" "github.com/hashicorp/vault/sdk/helper/consts" "github.com/hashicorp/vault/sdk/logical" ) @@ -93,6 +94,10 @@ func (c *Core) metricsLoop(stopCh chan struct{}) { // Refresh gauge metrics that are looped c.cachedGaugeMetricsEmitter() + // If we're using a raft backend, emit boltdb metrics + if rb, ok := c.underlyingPhysical.(*raft.RaftBackend); ok { + rb.CollectMetrics(c.MetricSink()) + } case <-writeTimer: if stopped := grabLockOrStop(c.stateLock.RLock, c.stateLock.RUnlock, stopCh); stopped { // Go through the loop again, this time the stop channel case @@ -132,7 +137,6 @@ func (c *Core) metricsLoop(stopCh chan struct{}) { metrics.SetGauge([]string{"identity", "num_entities"}, float32(entities.Entities.Total)) } }() - case <-stopCh: return } @@ -203,7 +207,6 @@ func (c *Core) emitMetrics(stopCh chan struct{}) { // // Both active nodes and performance standby nodes call emitMetrics // so we have to handle both. - metricsInit := []struct { MetricName []string MetadataLabel []metrics.Label diff --git a/vault/external_tests/metrics/core_metrics_int_test.go b/vault/external_tests/metrics/core_metrics_int_test.go index 40c9c8413..cc19ae0a7 100644 --- a/vault/external_tests/metrics/core_metrics_int_test.go +++ b/vault/external_tests/metrics/core_metrics_int_test.go @@ -8,9 +8,7 @@ import ( "testing" "time" - "github.com/armon/go-metrics" "github.com/hashicorp/vault/api" - "github.com/hashicorp/vault/helper/metricsutil" "github.com/hashicorp/vault/helper/testhelpers" vaulthttp "github.com/hashicorp/vault/http" "github.com/hashicorp/vault/vault" @@ -26,7 +24,7 @@ func TestMountTableMetrics(t *testing.T) { KeepStandbysSealed: false, HandlerFunc: vaulthttp.Handler, NumCores: 2, - CoreMetricSinkProvider: testMetricSinkProvider(time.Minute), + CoreMetricSinkProvider: testhelpers.TestMetricSinkProvider(time.Minute), }) cluster.Start() @@ -106,15 +104,6 @@ func gaugeConditionCheck(comparator string, compareVal int, compareToVal int) er return nil } -func testMetricSinkProvider(gaugeInterval time.Duration) func(string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper) { - return func(clusterName string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper) { - inm := metrics.NewInmemSink(1000000*time.Hour, 2000000*time.Hour) - clusterSink := metricsutil.NewClusterMetricSink(clusterName, inm) - clusterSink.GaugeInterval = gaugeInterval - return clusterSink, metricsutil.NewMetricsHelper(inm, false) - } -} - func TestLeaderReElectionMetrics(t *testing.T) { clusterName := "mycluster" conf := &vault.CoreConfig{ @@ -125,7 +114,7 @@ func TestLeaderReElectionMetrics(t *testing.T) { KeepStandbysSealed: false, HandlerFunc: vaulthttp.Handler, NumCores: 2, - CoreMetricSinkProvider: testMetricSinkProvider(time.Minute), + CoreMetricSinkProvider: testhelpers.TestMetricSinkProvider(time.Minute), }) cluster.Start() diff --git a/vault/external_tests/raft/raft_test.go b/vault/external_tests/raft/raft_test.go index 13db5736e..ab14395fb 100644 --- a/vault/external_tests/raft/raft_test.go +++ b/vault/external_tests/raft/raft_test.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/vault/helper/testhelpers" "github.com/hashicorp/vault/helper/testhelpers/teststorage" vaulthttp "github.com/hashicorp/vault/http" + "github.com/hashicorp/vault/internalshared/configutil" "github.com/hashicorp/vault/physical/raft" "github.com/hashicorp/vault/sdk/logical" "github.com/hashicorp/vault/vault" @@ -68,6 +69,62 @@ func raftCluster(t testing.TB, ropts *RaftClusterOpts) *vault.TestCluster { return cluster } +func TestRaft_BoltDBMetrics(t *testing.T) { + t.Parallel() + conf := vault.CoreConfig{} + opts := vault.TestClusterOptions{ + HandlerFunc: vaulthttp.Handler, + NumCores: 1, + CoreMetricSinkProvider: testhelpers.TestMetricSinkProvider(time.Minute), + DefaultHandlerProperties: vault.HandlerProperties{ + ListenerConfig: &configutil.Listener{ + Telemetry: configutil.ListenerTelemetry{ + UnauthenticatedMetricsAccess: true, + }, + }, + }, + } + + teststorage.RaftBackendSetup(&conf, &opts) + cluster := vault.NewTestCluster(t, &conf, &opts) + cluster.Start() + defer cluster.Cleanup() + + vault.TestWaitActive(t, cluster.Cores[0].Core) + leaderClient := cluster.Cores[0].Client + + // Write a few keys + for i := 0; i < 50; i++ { + _, err := leaderClient.Logical().Write(fmt.Sprintf("secret/%d", i), map[string]interface{}{ + fmt.Sprintf("foo%d", i): fmt.Sprintf("bar%d", i), + }) + if err != nil { + t.Fatal(err) + } + } + + // Even though there is a long delay between when we start the node and when we check for these metrics, + // the core metrics loop isn't started until postUnseal, which happens after said delay. This means we + // need a small artificial delay here as well, otherwise we won't see any metrics emitted. + time.Sleep(5 * time.Second) + data, err := testhelpers.SysMetricsReq(leaderClient, cluster, true) + if err != nil { + t.Fatal(err) + } + + noBoltDBMetrics := true + for _, g := range data.Gauges { + if strings.HasPrefix(g.Name, "raft_storage.bolt.") { + noBoltDBMetrics = false + break + } + } + + if noBoltDBMetrics { + t.Fatal("expected to find boltdb metrics being emitted from the raft backend, but there were none") + } +} + func TestRaft_RetryAutoJoin(t *testing.T) { t.Parallel() diff --git a/vault/testing.go b/vault/testing.go index 6361292d4..d4a8b5a95 100644 --- a/vault/testing.go +++ b/vault/testing.go @@ -1606,7 +1606,6 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te // Create TestClusterCores var ret []*TestClusterCore for i := 0; i < numCores; i++ { - tcc := &TestClusterCore{ Core: cores[i], CoreConfig: coreConfigs[i], diff --git a/vendor/github.com/hashicorp/raft-boltdb/v2/LICENSE b/vendor/github.com/hashicorp/raft-boltdb/v2/LICENSE new file mode 100644 index 000000000..f0e5c79e1 --- /dev/null +++ b/vendor/github.com/hashicorp/raft-boltdb/v2/LICENSE @@ -0,0 +1,362 @@ +Mozilla Public License, version 2.0 + +1. Definitions + +1.1. "Contributor" + + means each individual or legal entity that creates, contributes to the + creation of, or owns Covered Software. + +1.2. "Contributor Version" + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + + means Source Code Form to which the initial Contributor has attached the + notice in Exhibit A, the Executable Form of such Source Code Form, and + Modifications of such Source Code Form, in each case including portions + thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + a. that the initial Contributor has attached the notice described in + Exhibit B to the Covered Software; or + + b. that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the terms of + a Secondary License. + +1.6. "Executable Form" + + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + + means a work that combines Covered Software with other material, in a + separate file or files, that is not Covered Software. + +1.8. "License" + + means this document. + +1.9. "Licensable" + + means having the right to grant, to the maximum extent possible, whether + at the time of the initial grant or subsequently, any and all of the + rights conveyed by this License. + +1.10. "Modifications" + + means any of the following: + + a. any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered Software; or + + b. any new file in Source Code Form that contains any Covered Software. + +1.11. "Patent Claims" of a Contributor + + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the License, + by the making, using, selling, offering for sale, having made, import, + or transfer of either its Contributions or its Contributor Version. + +1.12. "Secondary License" + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public + License, Version 3.0, or any later versions of those licenses. + +1.13. "Source Code Form" + + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that controls, is + controlled by, or is under common control with You. For purposes of this + definition, "control" means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (b) ownership of more than fifty percent (50%) of the + outstanding shares or beneficial ownership of such entity. + + +2. License Grants and Conditions + +2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + a. under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + + b. under Patent Claims of such Contributor to make, use, sell, offer for + sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution + become effective for each Contribution on the date the Contributor first + distributes such Contribution. + +2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under + this License. No additional rights or licenses will be implied from the + distribution or licensing of Covered Software under this License. + Notwithstanding Section 2.1(b) above, no patent license is granted by a + Contributor: + + a. for any code that a Contributor has removed from Covered Software; or + + b. for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. under Patent Claims infringed by Covered Software in the absence of + its Contributions. + + This License does not grant any rights in the trademarks, service marks, + or logos of any Contributor (except as may be necessary to comply with + the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to + distribute the Covered Software under a subsequent version of this + License (see Section 10.2) or under the terms of a Secondary License (if + permitted under the terms of Section 3.3). + +2.5. Representation + + Each Contributor represents that the Contributor believes its + Contributions are its original creation(s) or it has sufficient rights to + grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + + This License is not intended to limit any rights You have under + applicable copyright doctrines of fair use, fair dealing, or other + equivalents. + +2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities + +3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under + the terms of this License. You must inform recipients that the Source + Code Form of the Covered Software is governed by the terms of this + License, and how they can obtain a copy of this License. You may not + attempt to alter or restrict the recipients' rights in the Source Code + Form. + +3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. such Covered Software must also be made available in Source Code Form, + as described in Section 3.1, and You must inform recipients of the + Executable Form how they can obtain a copy of such Source Code Form by + reasonable means in a timely manner, at a charge no more than the cost + of distribution to the recipient; and + + b. You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter the + recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for + the Covered Software. If the Larger Work is a combination of Covered + Software with a work governed by one or more Secondary Licenses, and the + Covered Software is not Incompatible With Secondary Licenses, this + License permits You to additionally distribute such Covered Software + under the terms of such Secondary License(s), so that the recipient of + the Larger Work may, at their option, further distribute the Covered + Software under the terms of either this License or such Secondary + License(s). + +3.4. Notices + + You may not remove or alter the substance of any license notices + (including copyright notices, patent notices, disclaimers of warranty, or + limitations of liability) contained within the Source Code Form of the + Covered Software, except that You may alter any license notices to the + extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of Covered + Software. However, You may do so only on Your own behalf, and not on + behalf of any Contributor. You must make it absolutely clear that any + such warranty, support, indemnity, or liability obligation is offered by + You alone, and You hereby agree to indemnify every Contributor for any + liability incurred by such Contributor as a result of warranty, support, + indemnity or liability terms You offer. You may include additional + disclaimers of warranty and limitations of liability specific to any + jurisdiction. + +4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License + with respect to some or all of the Covered Software due to statute, + judicial order, or regulation then You must: (a) comply with the terms of + this License to the maximum extent possible; and (b) describe the + limitations and the code they affect. Such description must be placed in a + text file included with all distributions of the Covered Software under + this License. Except to the extent prohibited by statute or regulation, + such description must be sufficiently detailed for a recipient of ordinary + skill to be able to understand it. + +5. Termination + +5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, + then the rights granted under this License from a particular Contributor + are reinstated (a) provisionally, unless and until such Contributor + explicitly and finally terminates Your grants, and (b) on an ongoing + basis, if such Contributor fails to notify You of the non-compliance by + some reasonable means prior to 60 days after You have come back into + compliance. Moreover, Your grants from a particular Contributor are + reinstated on an ongoing basis if such Contributor notifies You of the + non-compliance by some reasonable means, this is the first time You have + received notice of non-compliance with this License from such + Contributor, and You become compliant prior to 30 days after Your receipt + of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, + counter-claims, and cross-claims) alleging that a Contributor Version + directly or indirectly infringes any patent, then the rights granted to + You by any and all Contributors for the Covered Software under Section + 2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + +6. Disclaimer of Warranty + + Covered Software is provided under this License on an "as is" basis, + without warranty of any kind, either expressed, implied, or statutory, + including, without limitation, warranties that the Covered Software is free + of defects, merchantable, fit for a particular purpose or non-infringing. + The entire risk as to the quality and performance of the Covered Software + is with You. Should any Covered Software prove defective in any respect, + You (not any Contributor) assume the cost of any necessary servicing, + repair, or correction. This disclaimer of warranty constitutes an essential + part of this License. No use of any Covered Software is authorized under + this License except under this disclaimer. + +7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including + negligence), contract, or otherwise, shall any Contributor, or anyone who + distributes Covered Software as permitted above, be liable to You for any + direct, indirect, special, incidental, or consequential damages of any + character including, without limitation, damages for lost profits, loss of + goodwill, work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses, even if such party shall have been + informed of the possibility of such damages. This limitation of liability + shall not apply to liability for death or personal injury resulting from + such party's negligence to the extent applicable law prohibits such + limitation. Some jurisdictions do not allow the exclusion or limitation of + incidental or consequential damages, so this exclusion and limitation may + not apply to You. + +8. Litigation + + Any litigation relating to this License may be brought only in the courts + of a jurisdiction where the defendant maintains its principal place of + business and such litigation shall be governed by laws of that + jurisdiction, without reference to its conflict-of-law provisions. Nothing + in this Section shall prevent a party's ability to bring cross-claims or + counter-claims. + +9. Miscellaneous + + This License represents the complete agreement concerning the subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. Any law or regulation which provides that + the language of a contract shall be construed against the drafter shall not + be used to construe this License against a Contributor. + + +10. Versions of the License + +10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section + 10.3, no one other than the license steward has the right to modify or + publish new versions of this License. Each version will be given a + distinguishing version number. + +10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version + of the License under which You originally received the Covered Software, + or under the terms of any subsequent version published by the license + steward. + +10.3. Modified Versions + + If you create software not governed by this License, and you want to + create a new license for such software, you may create and use a + modified version of this License if you rename the license and remove + any references to the name of the license steward (except to note that + such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary + Licenses If You choose to distribute Source Code Form that is + Incompatible With Secondary Licenses under the terms of this version of + the License, the notice described in Exhibit B of this License must be + attached. + +Exhibit A - Source Code Form License Notice + + This Source Code Form is subject to the + terms of the Mozilla Public License, v. + 2.0. If a copy of the MPL was not + distributed with this file, You can + obtain one at + http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, +then You may include the notice in a location (such as a LICENSE file in a +relevant directory) where a recipient would be likely to look for such a +notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice + + This Source Code Form is "Incompatible + With Secondary Licenses", as defined by + the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/vendor/github.com/hashicorp/raft-boltdb/v2/README.md b/vendor/github.com/hashicorp/raft-boltdb/v2/README.md new file mode 100644 index 000000000..a87b81942 --- /dev/null +++ b/vendor/github.com/hashicorp/raft-boltdb/v2/README.md @@ -0,0 +1,6 @@ +raft-boltdb/v2 +=========== + +This implementation uses the maintained version of BoltDB, [BBolt](https://github.com/etcd-io/bbolt). This is the primary version of `raft-boltdb` and should be used whenever possible. + +There is no breaking API change to the library. However, there is the potential for disk format incompatibilities so it was decided to be conservative and making it a separate import path. This separate import path will allow both versions (original and v2) to be imported to perform a safe in-place upgrade of old files read with the old version and written back out with the new one. \ No newline at end of file diff --git a/physical/raft/logstore/bolt_store.go b/vendor/github.com/hashicorp/raft-boltdb/v2/bolt_store.go similarity index 89% rename from physical/raft/logstore/bolt_store.go rename to vendor/github.com/hashicorp/raft-boltdb/v2/bolt_store.go index 6b46f7d68..4e75309e9 100644 --- a/physical/raft/logstore/bolt_store.go +++ b/vendor/github.com/hashicorp/raft-boltdb/v2/bolt_store.go @@ -1,16 +1,16 @@ -package logstore +package raftboltdb import ( "errors" "github.com/hashicorp/raft" - bolt "go.etcd.io/bbolt" + "go.etcd.io/bbolt" ) const ( // Permissions to use on the db file. This is only used if the // database file does not exist and needs to be created. - dbFileMode = 0o600 + dbFileMode = 0600 ) var ( @@ -22,25 +22,25 @@ var ( ErrKeyNotFound = errors.New("not found") ) -// BoltStore provides access to BoltDB for Raft to store and retrieve +// BoltStore provides access to Bbolt for Raft to store and retrieve // log entries. It also provides key/value storage, and can be used as // a LogStore and StableStore. type BoltStore struct { // conn is the underlying handle to the db. - conn *bolt.DB + conn *bbolt.DB // The path to the Bolt database file path string } -// Options contains all the configuration used to open the BoltDB +// Options contains all the configuration used to open the Bbolt type Options struct { - // Path is the file path to the BoltDB to use + // Path is the file path to the Bbolt to use Path string - // BoltOptions contains any specific BoltDB options you might + // BoltOptions contains any specific Bbolt options you might // want to specify [e.g. open timeout] - BoltOptions *bolt.Options + BoltOptions *bbolt.Options // NoSync causes the database to skip fsync calls after each // write to the log. This is unsafe, so it should be used @@ -60,10 +60,10 @@ func NewBoltStore(path string) (*BoltStore, error) { return New(Options{Path: path}) } -// New uses the supplied options to open the BoltDB and prepare it for use as a raft backend. +// New uses the supplied options to open the Bbolt and prepare it for use as a raft backend. func New(options Options) (*BoltStore, error) { // Try to connect - handle, err := bolt.Open(options.Path, dbFileMode, options.BoltOptions) + handle, err := bbolt.Open(options.Path, dbFileMode, options.BoltOptions) if err != nil { return nil, err } @@ -105,6 +105,10 @@ func (b *BoltStore) initialize() error { return tx.Commit() } +func (b *BoltStore) Stats() bbolt.Stats { + return b.conn.Stats() +} + // Close is used to gracefully close the DB connection. func (b *BoltStore) Close() error { return b.conn.Close() @@ -142,7 +146,7 @@ func (b *BoltStore) LastIndex() (uint64, error) { } } -// GetLog is used to retrieve a log from BoltDB at a given index. +// GetLog is used to retrieve a log from Bbolt at a given index. func (b *BoltStore) GetLog(idx uint64, log *raft.Log) error { tx, err := b.conn.Begin(false) if err != nil { @@ -156,7 +160,6 @@ func (b *BoltStore) GetLog(idx uint64, log *raft.Log) error { if val == nil { return raft.ErrLogNotFound } - return decodeMsgPack(val, log) } @@ -179,7 +182,6 @@ func (b *BoltStore) StoreLogs(logs []*raft.Log) error { if err != nil { return err } - bucket := tx.Bucket(dbLogs) if err := bucket.Put(key, val.Bytes()); err != nil { return err @@ -245,7 +247,6 @@ func (b *BoltStore) Get(k []byte) ([]byte, error) { if val == nil { return nil, ErrKeyNotFound } - return append([]byte(nil), val...), nil } diff --git a/vendor/github.com/hashicorp/raft-boltdb/v2/go.mod b/vendor/github.com/hashicorp/raft-boltdb/v2/go.mod new file mode 100644 index 000000000..2b589b622 --- /dev/null +++ b/vendor/github.com/hashicorp/raft-boltdb/v2/go.mod @@ -0,0 +1,9 @@ +module github.com/hashicorp/raft-boltdb/v2 + +go 1.12 + +require ( + github.com/hashicorp/go-msgpack v0.5.5 + github.com/hashicorp/raft v1.1.0 + go.etcd.io/bbolt v1.3.5 +) diff --git a/vendor/github.com/hashicorp/raft-boltdb/v2/go.sum b/vendor/github.com/hashicorp/raft-boltdb/v2/go.sum new file mode 100644 index 000000000..4ca5a0b45 --- /dev/null +++ b/vendor/github.com/hashicorp/raft-boltdb/v2/go.sum @@ -0,0 +1,39 @@ +github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM= +github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= +github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.9.1 h1:9PZfAcVEvez4yhLH2TBU64/h/z4xlFI80cWXRrxuKuM= +github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= +github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/raft v1.1.0 h1:qPMePEczgbkiQsqCsRfuHRqvDUO+zmAInDaD5ptXlq0= +github.com/hashicorp/raft v1.1.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= +go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/physical/raft/logstore/util.go b/vendor/github.com/hashicorp/raft-boltdb/v2/util.go similarity index 97% rename from physical/raft/logstore/util.go rename to vendor/github.com/hashicorp/raft-boltdb/v2/util.go index d35dde8cb..68dd786b7 100644 --- a/physical/raft/logstore/util.go +++ b/vendor/github.com/hashicorp/raft-boltdb/v2/util.go @@ -1,4 +1,4 @@ -package logstore +package raftboltdb import ( "bytes" diff --git a/vendor/modules.txt b/vendor/modules.txt index 2025fc4bd..790bfb699 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -612,6 +612,9 @@ github.com/hashicorp/raft # github.com/hashicorp/raft-autopilot v0.1.2 ## explicit github.com/hashicorp/raft-autopilot +# github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210421194847-a7e34179d62c +## explicit +github.com/hashicorp/raft-boltdb/v2 # github.com/hashicorp/raft-snapshot v1.0.3 ## explicit github.com/hashicorp/raft-snapshot