Skip to content

Commit

Permalink
fixup lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jgough committed Jan 21, 2025
1 parent 5e92001 commit 1347ba4
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewApp(version string, ikwid bool) *cli.App {
Usage: "common read only operations on datatrails merklelog verifiable data",
Flags: []cli.Flag{
&cli.StringFlag{Name: "loglevel", Value: "NOOP"},
&cli.Int64Flag{Name: "height", Value: 14, Usage: "override the massif height"},
&cli.Int64Flag{Name: "height", Value: int64(defaultMassifHeight), Usage: "override the massif height"},
&cli.StringFlag{
Name: "data-url", Aliases: []string{"u"},
Usage: "url to download merkle log data from. mutually exclusive with data-local; if neither option is supplied, DataTrails' live log data will be used",
Expand Down
10 changes: 3 additions & 7 deletions ediag.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func NewEventDiagCmd() *cli.Command {
// assets, this is true regardless of which tenancy the
// record is fetched from. Those same events will appear in
// the logs of all tenants they were shared with.
var err error
tenantIdentity, err = appEntry.LogTenant()
if err != nil {
return err
Expand Down Expand Up @@ -132,14 +131,11 @@ func NewEventDiagCmd() *cli.Command {
}
idTime := time.UnixMilli(unixMS)

logTenant, err := appEntry.LogTenant()
if err != nil {
return err
}

// TODO: log version 1 uses the uuid bytes of the log tenant
// so we need to handle that here as well as log version 0.
trieKey := massifs.NewTrieKey(
massifs.KeyTypeApplicationContent,
[]byte(logTenant),
[]byte(tenantIdentity),
[]byte(strings.TrimPrefix(appEntry.AppID(), "public")))
if len(trieKey) != massifs.TrieKeyBytes {
return massifs.ErrIndexEntryBadSize
Expand Down
6 changes: 5 additions & 1 deletion localwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/datatrails/go-datatrails-merklelog/massifs"
)

const (
readWriteAllPermission = 0666
)

// FileWriteAppendOpener is an interface for opening a file for writing
// The Open implementation must open for *append*, and must create the file if it does not exist.
// The Create implementation must truncate the file if it exists, and create it if it does not.
Expand All @@ -19,7 +23,7 @@ func (*FileWriteAppendOpener) Open(name string) (io.WriteCloser, error) {
if err != nil {
return nil, err
}
return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_APPEND, readWriteAllPermission)
}

// Create ensures the named file exists, is empty and is writable
Expand Down
2 changes: 1 addition & 1 deletion massifs.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ to produce the desired information computationaly produce
// massifs all have twice the amount of space reserved for
// the trie than we need.
trieDataSize := massifs.TrieEntryBytes * (1 << height)
peakStackSize := massifs.PeakStackLen(mi) * 32
peakStackSize := massifs.PeakStackLen(mi) * massifs.LogEntryBytes
switch cCtx.String("format") {
case tableFmtName:
row = fmt.Sprintf(tableSizesFmt, trieDataSize, peakStackSize) + row
Expand Down
4 changes: 2 additions & 2 deletions nodescan.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func NewNodeScanCmd() *cli.Command {
}
start := cmd.massif.LogStart()
count := cmd.massif.Count()
for i := uint64(0); i < count; i++ {
for i := range count {
entry := cmd.massif.Data[start+i*massifs.ValueBytes : start+i*massifs.ValueBytes+massifs.ValueBytes]
if bytes.Compare(entry, targetValue) == 0 {
if bytes.Equal(entry, targetValue) {
fmt.Printf("%d\n", i+cmd.massif.Start.FirstIndex)
return nil
}
Expand Down
12 changes: 9 additions & 3 deletions replicatelogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const (

// The default data retention policy is 2 years, so this is a generous default for "all data".
tenYearsOfHours = 10 * 365 * 24 * time.Hour

// jitterRangeMS is the range from 0 to jitter in milliseconds
jitterRangeMS = 100

// massifHeightMax is the maximum massif height
massifHeightMax = 255
)

var (
Expand Down Expand Up @@ -209,7 +215,7 @@ func replicateChanges(cCtx *cli.Context, cmd *CmdCtx, changes []TenantMassif, pr

var errs []error
for err := range errChan {
cmd.log.Infof(err.Error())
cmd.log.Infof("%v", err)
errs = append(errs, err)
}
if len(errs) > 0 {
Expand Down Expand Up @@ -239,7 +245,7 @@ func initReplication(cCtx *cli.Context, cmd *CmdCtx, change TenantMassif) (*Veri

func defaultRetryDelay(_ error) time.Duration {
// give the delay some jitter, this is universally a good practice
return baseDefaultRetryDelay + time.Duration(rand.Intn(100))*time.Millisecond
return baseDefaultRetryDelay + time.Duration(rand.Intn(jitterRangeMS))*time.Millisecond
}

func newProgressor(cCtx *cli.Context, barName string, increments int) Progresser {
Expand Down Expand Up @@ -277,7 +283,7 @@ func NewVerifiedReplica(
}

massifHeight := cCtx.Int64("height")
if massifHeight > 255 {
if massifHeight > massifHeightMax {
return nil, fmt.Errorf("massif height must be less than 256")
}

Expand Down
2 changes: 1 addition & 1 deletion tests/replicatelogs/replicatelogs_azurite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (s *ReplicateLogsCmdSuite) TestAncestorMassifLogsForOneTenant() {

if tt.ancestors >= massifCount-1 {
// then all massifs should be replicated
for i := uint32(0); i < massifCount; i++ {
for i := range massifCount {
expectMassifFile := filepath.Join(replicaDir, massifs.ReplicaRelativeMassifPath(tenantId0, i))
s.FileExistsf(expectMassifFile, "the replicated massif should exist")
expectSealFile := filepath.Join(replicaDir, massifs.ReplicaRelativeSealPath(tenantId0, i))
Expand Down
10 changes: 8 additions & 2 deletions timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

const (
millisecondMultiplier = 1000

nanoMultipler = 1e6
)

func NewTimestamp(id uint64, epoch uint8) (*timestamppb.Timestamp, error) {
ts := &timestamppb.Timestamp{}
err := SetTimestamp(id, ts, epoch)
Expand All @@ -20,8 +26,8 @@ func SetTimestamp(id uint64, ts *timestamppb.Timestamp, epoch uint8) error {
return err
}

ts.Seconds = ms / 1000
ts.Nanos = int32(uint64(ms)-(uint64(ts.GetSeconds())*1000)) * 1e6
ts.Seconds = ms / millisecondMultiplier
ts.Nanos = int32(uint64(ms)-(uint64(ts.GetSeconds())*millisecondMultiplier)) * nanoMultipler

return nil
}
28 changes: 19 additions & 9 deletions veracitytesting/testeventgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
const (
resourceChangedProperty = "resource_changed"
resourceChangeMerkleLogStoredEvent = "assetsv2merklelogeventstored"
millisecondMultiplier = int64(1000)
names = 2
assetAttributeWords = 4
eventAttributeWords = 6
)

type leafHasher interface {
Expand All @@ -45,15 +49,18 @@ func NewAzuriteTestContext(
t *testing.T,
testLabelPrefix string,
) (mmrtesting.TestContext, EventTestGenerator, mmrtesting.TestConfig) {

eventRate := 500

cfg := mmrtesting.TestConfig{
StartTimeMS: (1698342521) * 1000, EventRate: 500,
StartTimeMS: (1698342521) * millisecondMultiplier, EventRate: eventRate,
TestLabelPrefix: testLabelPrefix,
TenantIdentity: "",
Container: strings.ReplaceAll(strings.ToLower(testLabelPrefix), "_", "")}
leafHasher := NewLeafHasher()
tc := mmrtesting.NewTestContext(t, cfg)
g := NewEventTestGenerator(
t, cfg.StartTimeMS/1000,
t, cfg.StartTimeMS/millisecondMultiplier,
&leafHasher,
mmrtesting.TestGeneratorConfig{
StartTimeMS: cfg.StartTimeMS,
Expand Down Expand Up @@ -97,13 +104,16 @@ func (g *EventTestGenerator) NextId() (uint64, error) {
var err error
var id uint64

for i := 0; i < 2; i++ {
var attempts = 2
var sleep = time.Millisecond * 2

for range attempts {
id, err = g.IdState.NextID()
if err != nil {
if !errors.Is(err, snowflakeid.ErrOverloaded) {
return 0, err
}
time.Sleep(time.Millisecond * 2)
time.Sleep(sleep)
}
}
return id, nil
Expand All @@ -127,15 +137,15 @@ func (g *EventTestGenerator) GenerateLeaf(tenantIdentity string, base, i uint64)

func (g *EventTestGenerator) GenerateEventBatch(count int) []*assets.EventResponse {
events := make([]*assets.EventResponse, 0, count)
for i := 0; i < count; i++ {
for range count {
events = append(events, g.GenerateNextEvent(mmrtesting.DefaultGeneratorTenantIdentity))
}
return events
}

func (g *EventTestGenerator) GenerateTenantEventMessageBatch(tenantIdentity string, count int) []*azbus.ReceivedMessage {
msgs := make([]*azbus.ReceivedMessage, 0, count)
for i := 0; i < count; i++ {
for range count {
event := assets.EventMessage{
TenantId: tenantIdentity,
Event: g.GenerateNextEvent(tenantIdentity),
Expand All @@ -159,7 +169,7 @@ func (g *EventTestGenerator) GenerateNextEvent(tenantIdentity string) *assets.Ev
assetIdentity := g.NewAssetIdentity()
assetUUID := strings.Split(assetIdentity, "/")[1]

name := strings.Join(g.WordList(2), "")
name := strings.Join(g.WordList(names), "")
email := fmt.Sprintf("%[email protected]", name)
subject := strconv.Itoa(g.Intn(math.MaxInt))

Expand All @@ -184,14 +194,14 @@ func (g *EventTestGenerator) GenerateNextEvent(tenantIdentity string) *assets.Ev

"event-attribute-0": {
Value: &attribute.Attribute_StrVal{
StrVal: g.MultiWordString(6),
StrVal: g.MultiWordString(eventAttributeWords),
},
},
},
AssetAttributes: map[string]*attribute.Attribute{
"asset-attribute-0": {
Value: &attribute.Attribute_StrVal{
StrVal: g.MultiWordString(4),
StrVal: g.MultiWordString(assetAttributeWords),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func TestWatchForChanges(t *testing.T) {
}
if tt.wantOutputs != nil {
reporter := tt.args.reporter.(*mockReporter)
for i := 0; i < len(tt.wantOutputs); i++ {
for i := range tt.wantOutputs {
if i >= len(reporter.outf) {
t.Errorf("wanted %d outputs, got %d", len(tt.wantOutputs), len(reporter.outf))
break
Expand Down Expand Up @@ -469,7 +469,7 @@ func newFilterBlobItems(nameAndLastIdPairs ...string) []*azStorageBlob.FilterBlo
// just ignore odd lenght
var items []*azStorageBlob.FilterBlobItem
pairs := len(nameAndLastIdPairs) >> 1
for i := 0; i < pairs; i++ {
for i := range pairs {
name := nameAndLastIdPairs[i*2]
lastid := nameAndLastIdPairs[i*2+1]
items = append(items, newFilterBlobItem(name, lastid))
Expand Down

0 comments on commit 1347ba4

Please sign in to comment.