0
0
Fork 0

refactor scorch/zap command-line tools under bleve

zap command-line tool added to main bleve command-line tool
this required physical relocation due to the vendoring used
only on the bleve command-line tool (unforseen limitation)

a new scorch command-line tool has also been introduced
and for the same reasons it is physically store under
the top-level bleve command-line tool as well
This commit is contained in:
Marty Schoch 2018-01-05 10:17:18 -05:00
parent dee1dd9bc8
commit c691cd2bb5
14 changed files with 215 additions and 16 deletions

25
cmd/bleve/cmd/scorch.go Normal file
View File

@ -0,0 +1,25 @@
// Copyright (c) 2017 Couchbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
"github.com/blevesearch/bleve/cmd/bleve/cmd/scorch"
)
// make scorch command-line tool a bleve sub-command
func init() {
RootCmd.AddCommand(scorch.RootCmd)
}

View File

@ -0,0 +1,59 @@
// Copyright (c) 2017 Couchbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package scorch
import (
"fmt"
"github.com/spf13/cobra"
)
// dictCmd represents the dict command
var infoCmd = &cobra.Command{
Use: "info",
Short: "info prints basic info about the index",
Long: `The info command prints basic info about the index.`,
RunE: func(cmd *cobra.Command, args []string) error {
reader, err := index.Reader()
if err != nil {
return err
}
count, err := reader.DocCount()
if err != nil {
return err
}
fmt.Printf("count: %d\n", count)
// var numSnapshots int
// var rootSnapshot uint64
// index.VisitBoltSnapshots(func(snapshotEpoch uint64) error {
// if rootSnapshot == 0 {
// rootSnapshot = snapshotEpoch
// }
// numSnapshots++
// return nil
// })
// fmt.Printf("has %d snapshot(s), root: %d\n", numSnapshots, rootSnapshot)
return nil
},
}
func init() {
RootCmd.AddCommand(infoCmd)
}

View File

@ -0,0 +1,70 @@
// Copyright (c) 2017 Couchbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package scorch
import (
"fmt"
"os"
"github.com/blevesearch/bleve/index/scorch"
"github.com/spf13/cobra"
)
var index *scorch.Scorch
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "scorch",
Short: "command-line tool to interact with a scorch index",
Long: `Scorch is a command-line tool to interact with a scorch index.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("must specify path to scorch index")
}
readOnly := true
config := map[string]interface{}{
"read_only": readOnly,
"path": args[0],
}
idx, err := scorch.NewScorch(scorch.Name, config, nil)
if err != nil {
return err
}
err = idx.Open()
if err != nil {
return fmt.Errorf("error opening: %v", err)
}
index = idx.(*scorch.Scorch)
return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2017 Couchbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package scorch
import (
"fmt"
"github.com/spf13/cobra"
)
// snapshotsCmd represents the snapshots command
var snapshotCmd = &cobra.Command{
Use: "snapshot",
Short: "info prints details about the snapshots in the index",
Long: `The snapshot command prints details about the snapshots in the index.`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
snapshotEpochs, err := index.RootBoltSnapshotEpochs()
if err != nil {
return err
}
for _, snapshotEpoch := range snapshotEpochs {
fmt.Printf("%d\n", snapshotEpoch)
}
}
return nil
},
}
func init() {
RootCmd.AddCommand(snapshotCmd)
}

View File

@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package main
package cmd
import (
"github.com/blevesearch/bleve/index/scorch/segment/zap/cmd/zap/cmd"
"github.com/blevesearch/bleve/cmd/bleve/cmd/zap"
)
func main() {
cmd.Execute()
// make zap command-line tool a bleve sub-command
func init() {
RootCmd.AddCommand(zap.RootCmd)
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
package zap
import (
"encoding/binary"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
package zap
import (
"bytes"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
package zap
import (
"encoding/binary"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
package zap
import (
"encoding/binary"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
package zap
import (
"fmt"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
package zap
import (
"fmt"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
package zap
import (
"encoding/binary"

View File

@ -443,7 +443,7 @@ var NumSnapshotsToKeep = 1
// Removes enough snapshots from the rootBolt so that the
// s.eligibleForRemoval stays under the NumSnapshotsToKeep policy.
func (s *Scorch) removeOldBoltSnapshots() (numRemoved int, err error) {
persistedEpochs, err := s.rootBoltSnapshotEpochs()
persistedEpochs, err := s.RootBoltSnapshotEpochs()
if err != nil {
return 0, err
}
@ -565,7 +565,7 @@ func (s *Scorch) removeOldZapFiles() error {
return nil
}
func (s *Scorch) rootBoltSnapshotEpochs() ([]uint64, error) {
func (s *Scorch) RootBoltSnapshotEpochs() ([]uint64, error) {
var rv []uint64
err := s.rootBolt.View(func(tx *bolt.Tx) error {
snapshots := tx.Bucket(boltSnapshotsBucket)

View File

@ -1,3 +0,0 @@
# zap command line utility
Kind of a hack just put together quickly to let me debug some issues.