From 6c654c767279e9f20ff175d5cd932d5d2e128e2f Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 8 Jun 2024 17:29:53 +0530 Subject: [PATCH 1/9] add connection index --- .../go/0chain.net/blobbercore/allocation/allocationchange.go | 5 ++++- goose/migrations/1717845128_connection_index.sql | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 goose/migrations/1717845128_connection_index.sql diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index d835d7671..809c2ff57 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -95,7 +95,10 @@ func (ac *AllocationChange) BeforeSave(tx *gorm.DB) error { func (change *AllocationChange) Save(ctx context.Context) error { db := datastore.GetStore().GetTransaction(ctx) - return db.Save(change).Error + return db.Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "connection_id"}, {Name: "lookup_hash"}}, + DoUpdates: clause.AssignmentColumns([]string{"size", "input"}), + }).Create(change).Error } func (change *AllocationChange) Create(ctx context.Context) error { diff --git a/goose/migrations/1717845128_connection_index.sql b/goose/migrations/1717845128_connection_index.sql new file mode 100644 index 000000000..585f0274b --- /dev/null +++ b/goose/migrations/1717845128_connection_index.sql @@ -0,0 +1,5 @@ +-- +goose Up +-- +goose StatementBegin + +CREATE UNIQUE INDEX idx_allocation_changes_lookup_hash ON allocation_changes USING HASH(connection_id,lookup_hash); +-- +goose StatementEnd \ No newline at end of file From 55622704567ce3239e2ed45f5a15f371ff6470ff Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 8 Jun 2024 17:57:39 +0530 Subject: [PATCH 2/9] rmv connectionobj in update change --- .../allocation/file_changer_base.go | 2 +- .../handler/file_command_delete.go | 6 +-- .../handler/file_command_update.go | 52 ++++++++++--------- .../handler/file_command_upload.go | 28 ++-------- .../handler/object_operation_handler.go | 6 +-- 5 files changed, 37 insertions(+), 57 deletions(-) diff --git a/code/go/0chain.net/blobbercore/allocation/file_changer_base.go b/code/go/0chain.net/blobbercore/allocation/file_changer_base.go index 3bc327820..337ee9be4 100644 --- a/code/go/0chain.net/blobbercore/allocation/file_changer_base.go +++ b/code/go/0chain.net/blobbercore/allocation/file_changer_base.go @@ -94,7 +94,7 @@ type FileCommand interface { ProcessThumbnail(allocationObj *Allocation) error // UpdateChange update AllocationChangeProcessor. It will be president in db for committing transcation - UpdateChange(ctx context.Context, connectionObj *AllocationChangeCollector) error + UpdateChange(ctx context.Context) error // AddChange add Allocation change to db AddChange(ctx context.Context) error diff --git a/code/go/0chain.net/blobbercore/handler/file_command_delete.go b/code/go/0chain.net/blobbercore/handler/file_command_delete.go index b8b9ae0f2..936804971 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_delete.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_delete.go @@ -62,10 +62,8 @@ func (cmd *DeleteFileCommand) IsValidated(ctx context.Context, req *http.Request } // UpdateChange add DeleteFileChange in db -func (cmd *DeleteFileCommand) UpdateChange(ctx context.Context, connectionObj *allocation.AllocationChangeCollector) error { - connectionObj.AddChange(cmd.allocationChange, cmd.changeProcessor) - - return connectionObj.Save(ctx) +func (cmd *DeleteFileCommand) UpdateChange(ctx context.Context) error { + return nil } func (cmd *DeleteFileCommand) AddChange(ctx context.Context) error { diff --git a/code/go/0chain.net/blobbercore/handler/file_command_update.go b/code/go/0chain.net/blobbercore/handler/file_command_update.go index ef2458141..d8fe12d99 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_update.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_update.go @@ -205,30 +205,34 @@ func (cmd *UpdateFileCommand) reloadChange() { } // UpdateChange add UpdateFileChanger in db -func (cmd *UpdateFileCommand) UpdateChange(ctx context.Context, connectionObj *allocation.AllocationChangeCollector) error { - cmd.fileChanger.AllocationID = connectionObj.AllocationID - for _, c := range connectionObj.Changes { - filePath, _ := c.GetOrParseAffectedFilePath() - if c.Operation != sdkConst.FileOperationUpdate || cmd.fileChanger.Path != filePath { - continue - } - - c.Size = connectionObj.Size - c.Input, _ = cmd.fileChanger.Marshal() - - //c.ModelWithTS.UpdatedAt = time.Now() - err := connectionObj.Save(ctx) - if err != nil { - return err - } - - return c.Save(ctx) - } - - //NOT FOUND - connectionObj.AddChange(cmd.allocationChange, cmd.fileChanger) - - return connectionObj.Save(ctx) +func (cmd *UpdateFileCommand) UpdateChange(ctx context.Context) error { + // cmd.fileChanger.AllocationID = connectionObj.AllocationID + // for _, c := range connectionObj.Changes { + // filePath, _ := c.GetOrParseAffectedFilePath() + // if c.Operation != sdkConst.FileOperationUpdate || cmd.fileChanger.Path != filePath { + // continue + // } + + // c.Size = connectionObj.Size + // c.Input, _ = cmd.fileChanger.Marshal() + + // //c.ModelWithTS.UpdatedAt = time.Now() + // err := connectionObj.Save(ctx) + // if err != nil { + // return err + // } + + // return c.Save(ctx) + // } + + // //NOT FOUND + // connectionObj.AddChange(cmd.allocationChange, cmd.fileChanger) + + // return connectionObj.Save(ctx) + connectionInput, _ := cmd.fileChanger.Marshal() + cmd.allocationChange.LookupHash = cmd.existingFileRef.LookupHash + cmd.allocationChange.Input = connectionInput + return cmd.allocationChange.Save(ctx) } func (cmd *UpdateFileCommand) AddChange(ctx context.Context) error { diff --git a/code/go/0chain.net/blobbercore/handler/file_command_upload.go b/code/go/0chain.net/blobbercore/handler/file_command_upload.go index ded271b1e..0f1c72251 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_upload.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_upload.go @@ -223,29 +223,11 @@ func (cmd *UploadFileCommand) reloadChange() { } // UpdateChange replace AddFileChange in db -func (cmd *UploadFileCommand) UpdateChange(ctx context.Context, connectionObj *allocation.AllocationChangeCollector) error { - cmd.fileChanger.AllocationID = connectionObj.AllocationID - for _, c := range connectionObj.Changes { - filePath, _ := c.GetOrParseAffectedFilePath() - if c.Operation != constants.FileOperationInsert || cmd.fileChanger.Path != filePath { - continue - } - c.Size = cmd.fileChanger.Size - c.Input, _ = cmd.fileChanger.Marshal() - - //c.ModelWithTS.UpdatedAt = time.Now() - err := connectionObj.Save(ctx) - if err != nil { - return err - } - - return c.Save(ctx) - } - - //NOT FOUND - connectionObj.AddChange(cmd.allocationChange, cmd.fileChanger) - - return connectionObj.Save(ctx) +func (cmd *UploadFileCommand) UpdateChange(ctx context.Context) error { + connectionInput, _ := cmd.fileChanger.Marshal() + cmd.allocationChange.LookupHash = reference.GetReferenceLookup(cmd.fileChanger.AllocationID, cmd.fileChanger.Path) + cmd.allocationChange.Input = connectionInput + return cmd.allocationChange.Save(ctx) } func (cmd *UploadFileCommand) AddChange(ctx context.Context) error { diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index 3144d1054..4416880c8 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -1297,11 +1297,7 @@ func (fsh *StorageHandler) WriteFile(ctx context.Context, r *http.Request) (*all } // Update/Save the change if res.UpdateChange { - dbConnectionObj, err := allocation.GetAllocationChanges(ctx, connectionID, allocationID, clientID) - if err != nil { - return nil, err - } - err = cmd.UpdateChange(ctx, dbConnectionObj) + err = cmd.UpdateChange(ctx) if err != nil { return nil, err } From 6ec4f6b87c334b5f37aa03ef9d2ac679923405aa Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 8 Jun 2024 18:18:48 +0530 Subject: [PATCH 3/9] use updates gorm --- .../0chain.net/blobbercore/allocation/allocationchange.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 809c2ff57..108ca9626 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -95,10 +95,10 @@ func (ac *AllocationChange) BeforeSave(tx *gorm.DB) error { func (change *AllocationChange) Save(ctx context.Context) error { db := datastore.GetStore().GetTransaction(ctx) - return db.Clauses(clause.OnConflict{ - Columns: []clause.Column{{Name: "connection_id"}, {Name: "lookup_hash"}}, - DoUpdates: clause.AssignmentColumns([]string{"size", "input"}), - }).Create(change).Error + return db.Table(change.TableName()).Where("connection_id = ? and lookup_hash = ?", change.ConnectionID, change.LookupHash).Updates(map[string]interface{}{ + "size": change.Size, + "input": change.Input, + }).Error } func (change *AllocationChange) Create(ctx context.Context) error { From a91f6daf9775e81d0c14311a2089c4de8bfd38f5 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 8 Jun 2024 18:37:50 +0530 Subject: [PATCH 4/9] add timings in apply changes --- .../0chain.net/blobbercore/allocation/allocationchange.go | 6 ++++++ .../blobbercore/handler/object_operation_handler.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 108ca9626..6445f5865 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -221,10 +221,12 @@ func (cc *AllocationChangeCollector) ComputeProperties() { func (cc *AllocationChangeCollector) ApplyChanges(ctx context.Context, allocationRoot, prevAllocationRoot string, ts common.Timestamp, fileIDMeta map[string]string) (*reference.Ref, error) { + now := time.Now() rootRef, err := cc.GetRootRef(ctx) if err != nil { return rootRef, err } + elapsedRootRef := time.Since(now) if rootRef.Hash != prevAllocationRoot { return rootRef, common.NewError("invalid_prev_root", "Invalid prev root") } @@ -235,12 +237,16 @@ func (cc *AllocationChangeCollector) ApplyChanges(ctx context.Context, allocatio return rootRef, err } } + elapsedApplyChanges := time.Since(now) - elapsedRootRef collector := reference.NewCollector(len(cc.Changes)) _, err = rootRef.CalculateHash(ctx, true, collector) if err != nil { return rootRef, err } + elapsedCalculateHash := time.Since(now) - elapsedApplyChanges - elapsedRootRef err = collector.Finalize(ctx) + elapsedFinalize := time.Since(now) - elapsedCalculateHash - elapsedApplyChanges - elapsedRootRef + logging.Logger.Info("applyChanges: ", zap.String("allocation_id", cc.AllocationID), zap.Duration("elapsedRootRef", elapsedRootRef), zap.Duration("elapsedApplyChanges", elapsedApplyChanges), zap.Duration("elapsedCalculateHash", elapsedCalculateHash), zap.Duration("elapsedFinalize", elapsedFinalize)) return rootRef, err } diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index 4416880c8..69422608b 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -671,7 +671,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b } elapsedApplyChanges := time.Since(startTime) - elapsedAllocation - elapsedGetLock - - elapsedGetConnObj - elapsedVerifyWM - elapsedWritePreRedeem + elapsedGetConnObj - elapsedVerifyWM - elapsedWritePreRedeem - elapsedMoveToFilestore allocationRoot := rootRef.Hash fileMetaRoot := rootRef.FileMetaHash From e397a01cb4557235d6cc9150328f2056bb7ffc72 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 8 Jun 2024 19:50:22 +0530 Subject: [PATCH 5/9] change pkey of allocation changes --- .../allocation/allocationchange.go | 5 ++-- .../handler/file_command_delete.go | 3 ++- .../handler/file_command_update.go | 27 ++----------------- .../handler/file_command_upload.go | 4 +-- .../1717416291_change_lookuphash.sql | 3 +-- .../1717845128_connection_index.sql | 4 ++- 6 files changed, 12 insertions(+), 34 deletions(-) diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 108ca9626..8130f4c5c 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -66,14 +66,13 @@ func (ac *AllocationChangeCollector) BeforeSave(tx *gorm.DB) error { } type AllocationChange struct { - ChangeID int64 `gorm:"column:id;primaryKey"` Size int64 `gorm:"column:size;not null;default:0"` Operation string `gorm:"column:operation;size:20;not null"` ConnectionID string `gorm:"column:connection_id;size:64;not null"` Connection AllocationChangeCollector `gorm:"foreignKey:ConnectionID"` // References allocation_connections(id) Input string `gorm:"column:input"` FilePath string `gorm:"-"` - LookupHash string `gorm:"column:lookup_hash;size:64"` + LookupHash string `gorm:"column:lookup_hash;primaryKey;size:64"` datastore.ModelWithTS } @@ -95,7 +94,7 @@ func (ac *AllocationChange) BeforeSave(tx *gorm.DB) error { func (change *AllocationChange) Save(ctx context.Context) error { db := datastore.GetStore().GetTransaction(ctx) - return db.Table(change.TableName()).Where("connection_id = ? and lookup_hash = ?", change.ConnectionID, change.LookupHash).Updates(map[string]interface{}{ + return db.Table(change.TableName()).Where("lookup_hash = ?", change.ConnectionID, change.LookupHash).Updates(map[string]interface{}{ "size": change.Size, "input": change.Input, }).Error diff --git a/code/go/0chain.net/blobbercore/handler/file_command_delete.go b/code/go/0chain.net/blobbercore/handler/file_command_delete.go index 936804971..61c12a5bf 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_delete.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_delete.go @@ -11,6 +11,7 @@ import ( "github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference" "github.com/0chain/blobber/code/go/0chain.net/core/common" + "github.com/0chain/blobber/code/go/0chain.net/core/encryption" ) // DeleteFileCommand command for deleting file @@ -91,7 +92,7 @@ func (cmd *DeleteFileCommand) ProcessContent(_ context.Context, allocationObj *a cmd.allocationChange.ConnectionID = connectionID cmd.allocationChange.Size = 0 - deleteSize cmd.allocationChange.Operation = constants.FileOperationDelete - cmd.allocationChange.LookupHash = cmd.existingFileRef.LookupHash + cmd.allocationChange.LookupHash = encryption.Hash(connectionID + cmd.path) allocation.UpdateConnectionObjSize(connectionID, cmd.allocationChange.Size) diff --git a/code/go/0chain.net/blobbercore/handler/file_command_update.go b/code/go/0chain.net/blobbercore/handler/file_command_update.go index d8fe12d99..b670cca3d 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_update.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_update.go @@ -206,38 +206,15 @@ func (cmd *UpdateFileCommand) reloadChange() { // UpdateChange add UpdateFileChanger in db func (cmd *UpdateFileCommand) UpdateChange(ctx context.Context) error { - // cmd.fileChanger.AllocationID = connectionObj.AllocationID - // for _, c := range connectionObj.Changes { - // filePath, _ := c.GetOrParseAffectedFilePath() - // if c.Operation != sdkConst.FileOperationUpdate || cmd.fileChanger.Path != filePath { - // continue - // } - - // c.Size = connectionObj.Size - // c.Input, _ = cmd.fileChanger.Marshal() - - // //c.ModelWithTS.UpdatedAt = time.Now() - // err := connectionObj.Save(ctx) - // if err != nil { - // return err - // } - - // return c.Save(ctx) - // } - - // //NOT FOUND - // connectionObj.AddChange(cmd.allocationChange, cmd.fileChanger) - - // return connectionObj.Save(ctx) connectionInput, _ := cmd.fileChanger.Marshal() - cmd.allocationChange.LookupHash = cmd.existingFileRef.LookupHash + cmd.allocationChange.LookupHash = encryption.Hash(cmd.fileChanger.ConnectionID + cmd.fileChanger.Path) cmd.allocationChange.Input = connectionInput return cmd.allocationChange.Save(ctx) } func (cmd *UpdateFileCommand) AddChange(ctx context.Context) error { connectionInput, _ := cmd.fileChanger.Marshal() - cmd.allocationChange.LookupHash = cmd.existingFileRef.LookupHash + cmd.allocationChange.LookupHash = encryption.Hash(cmd.fileChanger.ConnectionID + cmd.fileChanger.Path) cmd.allocationChange.Input = connectionInput return cmd.allocationChange.Create(ctx) } diff --git a/code/go/0chain.net/blobbercore/handler/file_command_upload.go b/code/go/0chain.net/blobbercore/handler/file_command_upload.go index 0f1c72251..31babffc5 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_upload.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_upload.go @@ -225,14 +225,14 @@ func (cmd *UploadFileCommand) reloadChange() { // UpdateChange replace AddFileChange in db func (cmd *UploadFileCommand) UpdateChange(ctx context.Context) error { connectionInput, _ := cmd.fileChanger.Marshal() - cmd.allocationChange.LookupHash = reference.GetReferenceLookup(cmd.fileChanger.AllocationID, cmd.fileChanger.Path) + cmd.allocationChange.LookupHash = encryption.Hash(cmd.fileChanger.ConnectionID + cmd.fileChanger.Path) cmd.allocationChange.Input = connectionInput return cmd.allocationChange.Save(ctx) } func (cmd *UploadFileCommand) AddChange(ctx context.Context) error { connectionInput, _ := cmd.fileChanger.Marshal() - cmd.allocationChange.LookupHash = reference.GetReferenceLookup(cmd.fileChanger.AllocationID, cmd.fileChanger.Path) + cmd.allocationChange.LookupHash = encryption.Hash(cmd.fileChanger.ConnectionID + cmd.fileChanger.Path) cmd.allocationChange.Input = connectionInput return cmd.allocationChange.Create(ctx) } diff --git a/goose/migrations/1717416291_change_lookuphash.sql b/goose/migrations/1717416291_change_lookuphash.sql index e2d8e71dd..7481b5e0b 100644 --- a/goose/migrations/1717416291_change_lookuphash.sql +++ b/goose/migrations/1717416291_change_lookuphash.sql @@ -1,6 +1,5 @@ -- +goose Up -- +goose StatementBegin -ALTER TABLE allocation_changes ADD COLUMN lookup_hash character varying(64); +ALTER TABLE allocation_changes ADD COLUMN lookup_hash character varying(64); --- CREATE UNIQUE INDEX idx_allocation_changes_lookup_hash ON allocation_changes USING HASH(lookup_hash,connection_id); -- +goose StatementEnd \ No newline at end of file diff --git a/goose/migrations/1717845128_connection_index.sql b/goose/migrations/1717845128_connection_index.sql index 585f0274b..812249c48 100644 --- a/goose/migrations/1717845128_connection_index.sql +++ b/goose/migrations/1717845128_connection_index.sql @@ -1,5 +1,7 @@ -- +goose Up -- +goose StatementBegin -CREATE UNIQUE INDEX idx_allocation_changes_lookup_hash ON allocation_changes USING HASH(connection_id,lookup_hash); +ALTER TABLE allocation_changes DROP CONSTRAINT allocation_changes_pkey CASCADE, +ADD CONSTRAINT allocation_changes_pkey PRIMARY KEY (lookup_hash); +ALTER TABLE allocation_changes DROP COLUMN id; -- +goose StatementEnd \ No newline at end of file From 4bcfed050e35df3a89276712d1a7ea796e7d253b Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 8 Jun 2024 20:58:25 +0530 Subject: [PATCH 6/9] fix test --- code/go/0chain.net/blobbercore/allocation/allocationchange.go | 1 + goose/migrations/1717845128_connection_index.sql | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 8130f4c5c..8308c5dc9 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -66,6 +66,7 @@ func (ac *AllocationChangeCollector) BeforeSave(tx *gorm.DB) error { } type AllocationChange struct { + ChangeID int64 `gorm:"column:id"` Size int64 `gorm:"column:size;not null;default:0"` Operation string `gorm:"column:operation;size:20;not null"` ConnectionID string `gorm:"column:connection_id;size:64;not null"` diff --git a/goose/migrations/1717845128_connection_index.sql b/goose/migrations/1717845128_connection_index.sql index 812249c48..c6bfc1093 100644 --- a/goose/migrations/1717845128_connection_index.sql +++ b/goose/migrations/1717845128_connection_index.sql @@ -3,5 +3,4 @@ ALTER TABLE allocation_changes DROP CONSTRAINT allocation_changes_pkey CASCADE, ADD CONSTRAINT allocation_changes_pkey PRIMARY KEY (lookup_hash); -ALTER TABLE allocation_changes DROP COLUMN id; -- +goose StatementEnd \ No newline at end of file From 0d6deded68b835b3077d6e334acc17d454f10712 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 8 Jun 2024 23:06:04 +0530 Subject: [PATCH 7/9] revert id changes --- code/go/0chain.net/blobbercore/allocation/allocationchange.go | 1 - goose/migrations/1717845128_connection_index.sql | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 8308c5dc9..8130f4c5c 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -66,7 +66,6 @@ func (ac *AllocationChangeCollector) BeforeSave(tx *gorm.DB) error { } type AllocationChange struct { - ChangeID int64 `gorm:"column:id"` Size int64 `gorm:"column:size;not null;default:0"` Operation string `gorm:"column:operation;size:20;not null"` ConnectionID string `gorm:"column:connection_id;size:64;not null"` diff --git a/goose/migrations/1717845128_connection_index.sql b/goose/migrations/1717845128_connection_index.sql index c6bfc1093..812249c48 100644 --- a/goose/migrations/1717845128_connection_index.sql +++ b/goose/migrations/1717845128_connection_index.sql @@ -3,4 +3,5 @@ ALTER TABLE allocation_changes DROP CONSTRAINT allocation_changes_pkey CASCADE, ADD CONSTRAINT allocation_changes_pkey PRIMARY KEY (lookup_hash); +ALTER TABLE allocation_changes DROP COLUMN id; -- +goose StatementEnd \ No newline at end of file From f2305580950a16ad668e7d74eb0c70c5df6af556 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Sat, 8 Jun 2024 23:45:45 +0530 Subject: [PATCH 8/9] fix delete update change --- .../0chain.net/blobbercore/handler/file_command_delete.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/handler/file_command_delete.go b/code/go/0chain.net/blobbercore/handler/file_command_delete.go index 61c12a5bf..22234e54d 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_delete.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_delete.go @@ -64,7 +64,11 @@ func (cmd *DeleteFileCommand) IsValidated(ctx context.Context, req *http.Request // UpdateChange add DeleteFileChange in db func (cmd *DeleteFileCommand) UpdateChange(ctx context.Context) error { - return nil + err := cmd.AddChange(ctx) + if err == gorm.ErrDuplicatedKey { + return nil + } + return err } func (cmd *DeleteFileCommand) AddChange(ctx context.Context) error { From 53736df4224e8cec4ed6531961c0a6117415041e Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Tue, 11 Jun 2024 13:20:05 +0530 Subject: [PATCH 9/9] add logs for chain size --- .../0chain.net/blobbercore/handler/object_operation_handler.go | 1 + code/go/0chain.net/blobbercore/handler/storage_handler.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index 69422608b..968326e11 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -601,6 +601,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b } if latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size != writeMarker.ChainSize { + logging.Logger.Error("latestWMCommit: ", zap.String("allocationRoot", latestWriteMarkerEntity.WM.AllocationRoot), zap.String("allocationID", allocationID), zap.Int64("latestWMChainLength", latestWriteMarkerEntity.WM.ChainSize), zap.Int64("connectionObjSize", connectionObj.Size), zap.Int64("writeMarkerChainSize", writeMarker.ChainSize)) return nil, common.NewErrorf("invalid_chain_size", "Invalid chain size. expected:%v got %v", latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size, writeMarker.ChainSize) } diff --git a/code/go/0chain.net/blobbercore/handler/storage_handler.go b/code/go/0chain.net/blobbercore/handler/storage_handler.go index 18bc75e4d..930266e80 100644 --- a/code/go/0chain.net/blobbercore/handler/storage_handler.go +++ b/code/go/0chain.net/blobbercore/handler/storage_handler.go @@ -21,6 +21,7 @@ import ( "github.com/0chain/blobber/code/go/0chain.net/blobbercore/writemarker" "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" . "github.com/0chain/blobber/code/go/0chain.net/core/logging" "github.com/0chain/blobber/code/go/0chain.net/core/node" ) @@ -639,6 +640,7 @@ func (fsh *StorageHandler) GetObjectTree(ctx context.Context, r *http.Request) ( if latestWM.Status == writemarker.Committed { latestWM.WM.ChainLength = 0 // start a new chain } + logging.Logger.Info("latestWMrefPath: ", zap.String("allocationRoot", latestWM.WM.AllocationRoot), zap.String("allocationID", allocationID), zap.Int64("latestWMChainLength", latestWM.WM.ChainSize)) refPathResult.LatestWM = &latestWM.WM } return &refPathResult, nil