From 66ca94e766749da3ff1ae373d402a1fb399399c4 Mon Sep 17 00:00:00 2001 From: Hitenjain14 <57557631+Hitenjain14@users.noreply.github.com> Date: Mon, 11 Nov 2024 19:13:42 +0530 Subject: [PATCH 1/2] fix duplicate dir (#1504) * fix duplicate dir * fix duplicate check --- .../blobbercore/allocation/newdirchange.go | 17 ++++++++++++++++- code/go/0chain.net/blobbercore/reference/ref.go | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/allocation/newdirchange.go b/code/go/0chain.net/blobbercore/allocation/newdirchange.go index 6d5778fd0..3db4ba3a4 100644 --- a/code/go/0chain.net/blobbercore/allocation/newdirchange.go +++ b/code/go/0chain.net/blobbercore/allocation/newdirchange.go @@ -11,6 +11,8 @@ import ( "github.com/0chain/blobber/code/go/0chain.net/blobbercore/util" "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/encryption" + "github.com/0chain/blobber/code/go/0chain.net/core/logging" + "go.uber.org/zap" "gorm.io/gorm" ) @@ -33,6 +35,19 @@ func (nf *NewDir) ApplyChange(ctx context.Context, if parentRef == nil || parentRef.ID == 0 { _, err = reference.Mkdir(ctx, nf.AllocationID, nf.Path, allocationVersion, ts, collector) } else { + collector.LockTransaction() + defer collector.UnlockTransaction() + dirLookupHash := reference.GetReferenceLookup(nf.AllocationID, nf.Path) + dRef, err := reference.GetLimitedRefFieldsByLookupHash(ctx, nf.AllocationID, dirLookupHash, []string{"id"}) + if err != nil && err != gorm.ErrRecordNotFound { + logging.Logger.Error("ApplyChange:Newdir", zap.Error(err)) + return err + } + err = nil + // already exists + if dRef != nil && dRef.ID != 0 { + return nil + } parentIDRef := &parentRef.ID newRef := reference.NewDirectoryRef() newRef.AllocationID = nf.AllocationID @@ -43,7 +58,7 @@ func (nf *NewDir) ApplyChange(ctx context.Context, newRef.Name = filepath.Base(nf.Path) newRef.PathLevel = len(strings.Split(strings.TrimRight(nf.Path, "/"), "/")) newRef.ParentID = parentIDRef - newRef.LookupHash = reference.GetReferenceLookup(nf.AllocationID, nf.Path) + newRef.LookupHash = dirLookupHash newRef.CreatedAt = ts newRef.UpdatedAt = ts newRef.FileMetaHash = encryption.FastHash(newRef.GetFileMetaHashData()) diff --git a/code/go/0chain.net/blobbercore/reference/ref.go b/code/go/0chain.net/blobbercore/reference/ref.go index 1068815c6..53df6c7da 100644 --- a/code/go/0chain.net/blobbercore/reference/ref.go +++ b/code/go/0chain.net/blobbercore/reference/ref.go @@ -256,6 +256,7 @@ func Mkdir(ctx context.Context, allocationID, destpath string, allocationVersion newRef.AllocationVersion = allocationVersion err = db.Create(newRef).Error if err != nil { + logging.Logger.Error("mkdir: failed to create directory", zap.Error(err), zap.String("path", fields[i])) return nil, err } collector.AddToCache(newRef) From 6c1952f7a60406fce35418a1b01392c52696204a Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Mon, 9 Dec 2024 23:15:13 +0700 Subject: [PATCH 2/2] update limit monthly --- code/go/0chain.net/blobbercore/config/config.go | 2 +- config/0chain_blobber.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index 7403ecb52..73c9e3bdf 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -32,7 +32,7 @@ func SetupDefaultConfig() { viper.SetDefault("rate_limiters.block_limit_request", 500) viper.SetDefault("rate_limiters.block_limit_monthly", 31250000) viper.SetDefault("rate_limiters.upload_limit_monthly", 31250000) - viper.SetDefault("rate_limiters.commit_limit_monthly", 30000) + viper.SetDefault("rate_limiters.commit_limit_monthly", 1000000000) viper.SetDefault("rate_limiters.commit_limit_daily", 1600) viper.SetDefault("rate_limiters.commit_zero_limit_daily", 400) viper.SetDefault("rate_limiters.max_connection_changes", 100) diff --git a/config/0chain_blobber.yaml b/config/0chain_blobber.yaml index 100a3788f..758bab823 100755 --- a/config/0chain_blobber.yaml +++ b/config/0chain_blobber.yaml @@ -76,7 +76,7 @@ rate_limiters: # Max upload limit in a month for a client. Default is 2000GB(the value needs to be in blocks which is data/64KB) upload_limit_monthly: 31250000 # Max commit limit in a month for a client. Default is 30000 - commit_limit_monthly: 30000 + commit_limit_monthly: 1000000000 # Max commit limit in a day for a client. Default is 1600 commit_limit_daily: 1600 # Max commit limit with size zero or less in a day for a client. Default is 400