Skip to content

Commit

Permalink
[no-release-notes] go/store/cmd/noms: Change root to use config.(*Res…
Browse files Browse the repository at this point in the history
…olver).GetDatabase.
  • Loading branch information
reltuk committed Nov 27, 2023
1 parent e7180e4 commit 9f946a5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 66 deletions.
68 changes: 6 additions & 62 deletions go/store/cmd/noms/noms_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@ import (
"context"
"fmt"
"os"
"strings"

flag "github.com/juju/gnuflag"

"github.com/dolthub/dolt/go/store/cmd/noms/util"
"github.com/dolthub/dolt/go/store/config"
"github.com/dolthub/dolt/go/store/d"
"github.com/dolthub/dolt/go/store/hash"
"github.com/dolthub/dolt/go/store/datas"
"github.com/dolthub/dolt/go/store/types"
)

var nomsRoot = &util.Command{
Run: runRoot,
UsageLine: "root <db-spec>",
Short: "Get or set the current root hash of the entire database",
Short: "Get the current root hash of the entire database",
Long: "See Spelling Objects at https://github.com/attic-labs/noms/blob/master/doc/spelling.md for details on the database argument.",
Flags: setupRootFlags,
Nargs: 1,
Expand All @@ -49,7 +48,6 @@ var updateRoot = ""

func setupRootFlags() *flag.FlagSet {
flagSet := flag.NewFlagSet("root", flag.ExitOnError)
flagSet.StringVar(&updateRoot, "update", "", "Replaces the entire database with the one with the given hash")
return flagSet
}

Expand All @@ -60,70 +58,16 @@ func runRoot(ctx context.Context, args []string) int {
}

cfg := config.NewResolver()
cs, err := cfg.GetChunkStore(ctx, args[0])
util.CheckErrorNoUsage(err)
defer cs.Close()

currRoot, err := cs.Root(ctx)

if err != nil {
fmt.Fprintln(os.Stderr, "error getting root.", err)
return 1
}

if updateRoot == "" {
fmt.Println(currRoot)
return 0
}

if updateRoot[0] == '#' {
updateRoot = updateRoot[1:]
}
h, ok := hash.MaybeParse(updateRoot)
if !ok {
fmt.Fprintf(os.Stderr, "Invalid hash: %s\n", h.String())
return 1
}

// If BUG 3407 is correct, we might be able to just take cs and make a Database directly from that.
db, vrw, _, err := cfg.GetDatabase(ctx, args[0])
db, _, _, err := cfg.GetDatabase(ctx, args[0])
util.CheckErrorNoUsage(err)
defer db.Close()
v, err := vrw.ReadValue(ctx, h)
util.CheckErrorNoUsage(err)
if !validate(ctx, vrw.Format(), v) {
return 1
}

fmt.Println(`WARNING
This operation replaces the entire database with the instance having the given
hash. The old database becomes eligible for GC.
ANYTHING NOT SAVED WILL BE LOST
Continue?`)

var input string
n, err := fmt.Scanln(&input)
util.CheckErrorNoUsage(err)
if n != 1 || strings.ToLower(input) != "y" {
return 0
}

ok, err = cs.Commit(ctx, h, currRoot)

currRoot, err := datas.ChunkStoreFromDatabase(db).Root(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "commit error: %s", err.Error())
return 1
}

if !ok {
fmt.Fprintln(os.Stderr, "Optimistic concurrency failure")
fmt.Fprintln(os.Stderr, "error getting root.", err)
return 1
}

fmt.Printf("Success. Previous root was: %s\n", currRoot)
fmt.Println(currRoot)
return 0
}

Expand Down
3 changes: 1 addition & 2 deletions go/store/cmd/noms/splunk.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

print "Welcome to the splunk shell for exploring dolt repository storage.\n";

my $manifest = `noms manifest $noms_dir`;
my $root = get_root($manifest);
my $root = `noms root $noms_dir`;

my $message = "Currently examining root.\nUse numeric labels to navigate the tree\n.. to back up a level, / to return to root.\nType quit or exit to exit.\n";

Expand Down
4 changes: 2 additions & 2 deletions go/store/datas/pull/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ func clone(ctx context.Context, srcTS, sinkTS chunks.TableFileStore, sinkCS chun
if _, sourceFiles, appendixFiles, err = srcTS.Sources(ctx); err != nil {
return err
} else {
tblFiles = filterAppendicesFromSourceFiles(appendixFiles, sourceFiles)
_, fileIDToTF, _ = mapTableFiles(tblFiles)
newTblFiles = filterAppendicesFromSourceFiles(appendixFiles, sourceFiles)
newDesired, newFileIDToTF, newFileIDToNumChunks := mapTableFiles(tblFiles)
}
}

Expand Down

0 comments on commit 9f946a5

Please sign in to comment.