|
| 1 | +// Copyright (c) 2017 Couchbase, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package scorch |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "strconv" |
| 20 | + |
| 21 | + "github.com/blevesearch/bleve/index/scorch/segment/zap" |
| 22 | + "github.com/spf13/cobra" |
| 23 | +) |
| 24 | + |
| 25 | +// snapshotCmd represents the snapshot command |
| 26 | +var snapshotCmd = &cobra.Command{ |
| 27 | + Use: "snapshot", |
| 28 | + Short: "info prints details about the snapshots in the index", |
| 29 | + Long: `The snapshot command prints details about the snapshots in the index.`, |
| 30 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 31 | + |
| 32 | + if len(args) < 2 { |
| 33 | + snapshotEpochs, err := index.RootBoltSnapshotEpochs() |
| 34 | + if err != nil { |
| 35 | + return err |
| 36 | + } |
| 37 | + for _, snapshotEpoch := range snapshotEpochs { |
| 38 | + fmt.Printf("%d\n", snapshotEpoch) |
| 39 | + } |
| 40 | + } else if len(args) < 3 { |
| 41 | + snapshotEpoch, err := strconv.ParseUint(args[1], 10, 64) |
| 42 | + if err != nil { |
| 43 | + return err |
| 44 | + } |
| 45 | + snapshot, err := index.LoadSnapshot(snapshotEpoch) |
| 46 | + if err != nil { |
| 47 | + return err |
| 48 | + } |
| 49 | + segments := snapshot.Segments() |
| 50 | + for i, segmentSnap := range segments { |
| 51 | + segment := segmentSnap.Segment() |
| 52 | + if segment, ok := segment.(*zap.Segment); ok { |
| 53 | + fmt.Printf("%d %s\n", i, segment.Path()) |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return nil |
| 59 | + }, |
| 60 | +} |
| 61 | + |
| 62 | +func init() { |
| 63 | + RootCmd.AddCommand(snapshotCmd) |
| 64 | +} |
0 commit comments