Skip to content

Commit

Permalink
Merge pull request #3886 from TrueBlocks/feature/indexManager
Browse files Browse the repository at this point in the history
Adds a devtool to check disc usage on various computers
  • Loading branch information
tjayrush authored Sep 20, 2024
2 parents adf79f4 + 20ab6cd commit a96c202
Show file tree
Hide file tree
Showing 15 changed files with 551 additions and 31 deletions.
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SymbolCache.noindex

chifra*
goMaker
indexManager
sdkFuzzer
makeClass
testRunner
Expand Down
23 changes: 12 additions & 11 deletions scripts/go-mod-tidy.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ set SCRIPT_DIR=%script_dir_backslash:~0,-1%
set ROOT_DIR=%SCRIPT_DIR%\..

:: Find all go.mod files and tidy them
cd /d %ROOT_DIR%\examples\balanceChart && go mod tidy
cd /d %ROOT_DIR%\examples\cancelContext && go mod tidy
cd /d %ROOT_DIR%\examples\findFirst && go mod tidy
cd /d %ROOT_DIR%\examples\nameManager && go mod tidy
cd /d %ROOT_DIR%\examples\simple && go mod tidy
cd /d %ROOT_DIR%\examples\withStreaming && go mod tidy
cd /d %ROOT_DIR%\src\apps\chifra && go mod tidy
cd /d %ROOT_DIR%\src\node && go mod tidy
cd /d %ROOT_DIR%\src\dev_tools\goMaker && go mod tidy
cd /d %ROOT_DIR%\src\dev_tools\sdkFuzzer && go mod tidy
cd /d %ROOT_DIR%\src\dev_tools\testRunner && go mod tidy
cd /d %ROOT_DIR%\examples\balanceChart && go mod tidy
cd /d %ROOT_DIR%\examples\cancelContext && go mod tidy
cd /d %ROOT_DIR%\examples\findFirst && go mod tidy
cd /d %ROOT_DIR%\examples\nameManager && go mod tidy
cd /d %ROOT_DIR%\examples\simple && go mod tidy
cd /d %ROOT_DIR%\examples\withStreaming && go mod tidy
cd /d %ROOT_DIR%\src\apps\chifra && go mod tidy
cd /d %ROOT_DIR%\src\node && go mod tidy
cd /d %ROOT_DIR%\src\dev_tools\goMaker && go mod tidy
cd /d %ROOT_DIR%\src\dev_tools\indexManager && go mod tidy
cd /d %ROOT_DIR%\src\dev_tools\sdkFuzzer && go mod tidy
cd /d %ROOT_DIR%\src\dev_tools\testRunner && go mod tidy

:: Return to the original directory and exit
exit /b
1 change: 1 addition & 0 deletions scripts/go-work-sync.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cd %ROOT_DIR% && go work use .\examples\withStreaming
cd %ROOT_DIR% && go work use .\src\apps\chifra
cd %ROOT_DIR% && go work use .\src\node
cd %ROOT_DIR% && go work use .\src\dev_tools\goMaker
cd %ROOT_DIR% && go work use .\src\dev_tools\indexManager
cd %ROOT_DIR% && go work use .\src\dev_tools\sdkFuzzer
cd %ROOT_DIR% && go work use .\src\dev_tools\testRunner

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ add_subdirectory(other/install)

ADD_GO_INSTALLABLE_PROGRAM(chifra ${CMAKE_SOURCE_DIR}/apps/chifra ${BIN_DIR})
ADD_GO_INSTALLABLE_PROGRAM(goMaker ${CMAKE_SOURCE_DIR}/dev_tools/goMaker ${BIN_DIR})
ADD_GO_INSTALLABLE_PROGRAM(indexManager ${CMAKE_SOURCE_DIR}/dev_tools/indexManager ${BIN_DIR})
if (NOT WIN32)
ADD_GO_INSTALLABLE_PROGRAM(testRunner ${CMAKE_SOURCE_DIR}/dev_tools/testRunner ${BIN_DIR})
ADD_GO_INSTALLABLE_PROGRAM(sdkFuzzer ${CMAKE_SOURCE_DIR}/dev_tools/sdkFuzzer ${BIN_DIR})
add_dependencies(testRunner goMaker)
add_dependencies(sdkFuzzer goMaker)
add_dependencies(indexManager goMaker)
add_dependencies(chifra testRunner)
endif()

Expand Down
14 changes: 14 additions & 0 deletions src/apps/chifra/internal/chunks/handle_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ func (opts *ChunksOptions) check(rCtx *output.RenderCtx, blockNums []base.Blknum
}
reports = append(reports, sizes)

// are all the hashes present?
contentCheck := types.ReportCheck{}
contentCheck.Reason = "Remote manifest contents"
if err := opts.CheckManContents(remoteManifest, &contentCheck); err != nil {
return err, false
}
reports = append(reports, contentCheck)

contentCheck.Reason = "Local manifest contents"
if err := opts.CheckManContents(remoteManifest, &contentCheck); err != nil {
return err, false
}
reports = append(reports, contentCheck)

// compare with çached manifest with files on disc
d2c := types.ReportCheck{Reason: "Disc files to cached manifest"}
if err := opts.CheckManifest(fnArray, cacheArray, &d2c); err != nil {
Expand Down
77 changes: 73 additions & 4 deletions src/apps/chifra/internal/chunks/handle_check_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"fmt"
"strings"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/version"
)

type CompareState struct {
Expand All @@ -22,9 +25,9 @@ type CompareState struct {
// failB int
}

// CheckManifest takes two arrays (either onDisc vs. LocalManifest, onDisc vs. RemoteManifest, or LocalManifest
// vs. RemoteManifest) and compares them for equality. If everything is up to date, all three arrays should
// be identical. Only the block ranges are in the arrays.
// CheckManifest takes two arrays (either onDisc vs. LocalManifest, onDisc vs. RemoteManifest,
// or LocalManifest vs. RemoteManifest) and compares them for equality. If everything is up
// to date, all three arrays should be identical. Only the block ranges are in the arrays.
func (opts *ChunksOptions) CheckManifest(arrayA, arrayB []string, report *types.ReportCheck) error {
comp := CompareState{
testMode: opts.Globals.TestMode,
Expand All @@ -46,7 +49,6 @@ func (opts *ChunksOptions) CheckManifest(arrayA, arrayB []string, report *types.
return comp.checkArrays(report)
}

// TODO: Can this be made concurrent?
func (comp *CompareState) checkArrays(report *types.ReportCheck) error {
marker := ""
if comp.testMode {
Expand Down Expand Up @@ -96,3 +98,70 @@ func (comp *CompareState) checkArrays(report *types.ReportCheck) error {

return nil
}

// CheckManContents spins through the manifest and makes sure all the
// bloom and index CIDs are present. It does not check that the CIDs are available.
func (opts *ChunksOptions) CheckManContents(man *manifest.Manifest, report *types.ReportCheck) error {
errs := []string{}

report.VisitedCnt += 3
report.CheckedCnt += 3

if !version.IsValidVersion(man.Version) {
errs = append(errs, "invalid version string "+opts.Tag)
} else {
report.PassedCnt++
}

if opts.Globals.Chain != man.Chain {
errs = append(errs, "different chains: globals("+opts.Globals.Chain+") manifest ("+man.Chain+")")
} else {
report.PassedCnt++
}

expectedSpec := config.SpecTags["[email protected]"]
if expectedSpec != man.Specification.String() {
errs = append(errs, "invalid spec "+man.Specification.String())
} else {
report.PassedCnt++
}

for _, chunk := range man.Chunks {
report.VisitedCnt++
report.CheckedCnt++
if len(chunk.Range) == 0 {
errs = append(errs, "empty range")
} else {
report.PassedCnt++
}

report.VisitedCnt++
report.CheckedCnt++
hasBloom := len(chunk.BloomHash) > 0
hasIndex := len(chunk.IndexHash) > 0
bloomSize := chunk.BloomSize > 0
indexSize := chunk.IndexSize > 0
if hasBloom && hasIndex && bloomSize && indexSize {
report.PassedCnt++
} else {
if !hasBloom {
errs = append(errs, chunk.Range+" - missing bloom hash")
}
if !hasIndex {
errs = append(errs, chunk.Range+" - missing index hash")
}
if !bloomSize {
errs = append(errs, chunk.Range+" - missing bloom size")
}
if !indexSize {
errs = append(errs, chunk.Range+" - missing index size")
}
}
}

if len(errs) > 0 {
report.MsgStrings = append(report.MsgStrings, errs...)
}

return nil
}
41 changes: 25 additions & 16 deletions src/apps/chifra/internal/chunks/handle_pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,49 @@ func (opts *ChunksOptions) HandlePin(rCtx *output.RenderCtx, blockNums []base.Bl
return rng1.First < rng2.First
})

for _, path := range fileList {
failCnt := 1.0
for i := 0; i < len(fileList); i++ {
sleep := opts.Sleep

path := fileList[i]
if opts.Globals.Verbose {
logger.Info("pinning path:", path)
}

local, remote, err := pinning.PinOneChunk(chain, path, opts.Remote)
if err != nil {
errorChan <- err
logger.Error("Pin failed:", path, err)
}

blMatches, idxMatches := matches(&local, &remote)
opts.matchReport(blMatches, local.BloomHash, remote.BloomHash)
opts.matchReport(idxMatches, local.IndexHash, remote.IndexHash)
failCnt *= 2.
sleep = failCnt
i-- // try again after sleeping for a bit
logger.Info(colors.Yellow, "Sleeping for", sleep, "seconds then trying again.", colors.Off)

if opts.Remote {
man.Chunks = append(man.Chunks, remote)
} else {
man.Chunks = append(man.Chunks, local)
}
_ = man.SaveManifest(chain, outPath)
blMatches, idxMatches := matches(&local, &remote)
opts.matchReport(blMatches, local.BloomHash, remote.BloomHash)
opts.matchReport(idxMatches, local.IndexHash, remote.IndexHash)

if opts.Globals.Verbose {
if opts.Remote {
fmt.Println("result.Remote:", remote.String())
man.Chunks = append(man.Chunks, remote)
} else {
fmt.Println("result.Local:", local.String())
man.Chunks = append(man.Chunks, local)
}
_ = man.SaveManifest(chain, outPath)

if opts.Globals.Verbose {
if opts.Remote {
fmt.Println("result.Remote:", remote.String())
} else {
fmt.Println("result.Local:", local.String())
}
}
}

sleep := opts.Sleep
if sleep > 0 {
ms := time.Duration(sleep*1000) * time.Millisecond
if !opts.Globals.TestMode {
logger.Info(fmt.Sprintf("Sleeping for %g seconds", sleep))
logger.Info("Sleeping for", sleep, "seconds")
}
time.Sleep(ms)
}
Expand Down
1 change: 1 addition & 0 deletions src/dev_tools/indexManager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disc_usage_report.md
3 changes: 3 additions & 0 deletions src/dev_tools/indexManager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# indexManager

The `indexManager` tool is for internal use only.
Loading

0 comments on commit a96c202

Please sign in to comment.