Skip to content

Commit 28ea8c0

Browse files
lpolipeterlimgcnlangzi
authored
Fix/update attributes (#717)
* Remove whopays attribute * Remove dot logger * Fix hashes of test * Remove redundant payer id field * Remove authticket association with readmarker * Fix conflicts * Remove proto file * Update go modules * Generate/Update grpc code * Go mod tidy * Remove payer in test insertion * Make reader pay for read instead of owner * Go mod tidy Co-authored-by: peterlimg <54137706+peterlimg@users.noreply.github.com> Co-authored-by: peterlimg <peterlimg@protonmail.com> Co-authored-by: Lz <imlangzi@qq.com>
1 parent 6b072d0 commit 28ea8c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+568
-1966
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ dev.local/data
1616
out/
1717
**/tmp/
1818
*.tar.gz
19+
**/descriptor.proto

code/go/0chain.net/blobbercore/allocation/allocationchange.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ func (cc *AllocationChangeCollector) ComputeProperties() {
148148
acp = new(RenameFileChange)
149149
case constants.FileOperationCopy:
150150
acp = new(CopyFileChange)
151-
case constants.FileOperationUpdateAttrs:
152-
acp = new(AttributesChange)
153151
}
154152

155153
if acp == nil {
Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1 @@
11
package allocation
2-
3-
import (
4-
"context"
5-
"encoding/json"
6-
"path/filepath"
7-
8-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
9-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/stats"
10-
"github.com/0chain/blobber/code/go/0chain.net/core/common"
11-
12-
. "github.com/0chain/blobber/code/go/0chain.net/core/logging"
13-
"go.uber.org/zap"
14-
)
15-
16-
// The AttributesChange represents file attributes change.
17-
type AttributesChange struct {
18-
ConnectionID string `json:"connection_id"`
19-
AllocationID string `json:"allocation_id"`
20-
Path string `json:"path"`
21-
Attributes *reference.Attributes `json:"attributes"` // new attributes
22-
}
23-
24-
// ApplyChange processes the attributes changes.
25-
func (ac *AttributesChange) ApplyChange(ctx context.Context, _ *AllocationChange, allocRoot string) (ref *reference.Ref, err error) {
26-
var path, _ = filepath.Split(ac.Path)
27-
path = filepath.Clean(path)
28-
29-
// root reference
30-
ref, err = reference.GetReferencePath(ctx, ac.AllocationID, ac.Path)
31-
32-
if err != nil {
33-
return nil, common.NewErrorf("process_attrs_update",
34-
"getting root reference path: %v", err)
35-
}
36-
37-
var (
38-
tSubDirs = reference.GetSubDirsFromPath(path)
39-
dirRef = ref
40-
treelevel = 0
41-
)
42-
dirRef.HashToBeComputed = true
43-
for treelevel < len(tSubDirs) {
44-
var found bool
45-
for _, child := range dirRef.Children {
46-
if child.Type == reference.DIRECTORY && treelevel < len(tSubDirs) {
47-
if child.Name == tSubDirs[treelevel] {
48-
dirRef, found = child, true
49-
dirRef.HashToBeComputed = true
50-
break
51-
}
52-
}
53-
}
54-
if found {
55-
treelevel++
56-
} else {
57-
return nil, common.NewError("process_attrs_update",
58-
"invalid reference path from the blobber")
59-
}
60-
}
61-
62-
var idx = -1
63-
for i, child := range dirRef.Children {
64-
if child.Type == reference.FILE && child.Path == ac.Path {
65-
idx = i
66-
break
67-
}
68-
}
69-
70-
if idx < 0 {
71-
Logger.Error("error in file attributes update", zap.Any("change", ac))
72-
return nil, common.NewError("process_attrs_update",
73-
"file to update not found in blobber")
74-
}
75-
76-
var existingRef = dirRef.Children[idx]
77-
existingRef.WriteMarker = allocRoot
78-
if err = existingRef.SetAttributes(ac.Attributes); err != nil {
79-
return nil, common.NewErrorf("process_attrs_update",
80-
"setting new attributes: %v", err)
81-
}
82-
83-
existingRef.HashToBeComputed = true
84-
85-
if _, err := ref.CalculateHash(ctx, true); err != nil {
86-
return nil, common.NewErrorf("process_attrs_update",
87-
"saving updated reference: %v", err)
88-
}
89-
90-
stats.FileUpdated(ctx, existingRef.ID)
91-
return
92-
}
93-
94-
// Marshal to JSON-string.
95-
func (ac *AttributesChange) Marshal() (val string, err error) {
96-
var b []byte
97-
if b, err = json.Marshal(ac); err != nil {
98-
return
99-
}
100-
return string(b), nil
101-
}
102-
103-
// Unmarshal from given JSON-string.
104-
func (ac *AttributesChange) Unmarshal(val string) (err error) {
105-
err = json.Unmarshal([]byte(val), ac)
106-
return
107-
}
108-
109-
// The DeleteTempFile returns OperationNotApplicable error.
110-
func (ac *AttributesChange) DeleteTempFile() (err error) {
111-
return nil
112-
}
113-
114-
// The CommitToFileStore does nothing.
115-
func (ac *AttributesChange) CommitToFileStore(_ context.Context) (err error) {
116-
return
117-
}

code/go/0chain.net/blobbercore/allocation/copyfilechange.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ package allocation
33
import (
44
"context"
55
"encoding/json"
6-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
76
"path/filepath"
87

8+
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
9+
910
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
1011
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/stats"
1112
"github.com/0chain/blobber/code/go/0chain.net/core/common"
12-
13-
"gorm.io/datatypes"
1413
)
1514

1615
type CopyFileChange struct {
@@ -133,7 +132,6 @@ func (rf *CopyFileChange) processCopyRefs(ctx context.Context, affectedRef, dest
133132
newRef.ParentPath = destRef.Path
134133
newRef.Name = affectedRef.Name
135134
newRef.LookupHash = reference.GetReferenceLookup(newRef.AllocationID, newRef.Path)
136-
newRef.Attributes = datatypes.JSON(string(affectedRef.Attributes))
137135
newRef.HashToBeComputed = true
138136
destRef.AddChild(newRef)
139137

@@ -160,7 +158,6 @@ func (rf *CopyFileChange) processCopyRefs(ctx context.Context, affectedRef, dest
160158
newFile.ActualThumbnailHash = affectedRef.ActualThumbnailHash
161159
newFile.ActualThumbnailSize = affectedRef.ActualThumbnailSize
162160
newFile.EncryptedKey = affectedRef.EncryptedKey
163-
newFile.Attributes = datatypes.JSON(string(affectedRef.Attributes))
164161
newFile.ChunkSize = affectedRef.ChunkSize
165162
newFile.HashToBeComputed = true
166163
destRef.AddChild(newFile)

code/go/0chain.net/blobbercore/allocation/entity.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type Allocation struct {
3838
OwnerID string `gorm:"column:owner_id;size:64;not null"`
3939
OwnerPublicKey string `gorm:"column:owner_public_key;size:512;not null"`
4040
RepairerID string `gorm:"column:repairer_id;size:64;not null"`
41-
PayerID string `gorm:"column:payer_id;size:64;not null"`
4241
Expiration common.Timestamp `gorm:"column:expiration_date;not null"`
4342
// AllocationRoot allcation_root of last write_marker
4443
AllocationRoot string `gorm:"column:allocation_root;size:64;not null;default:''"`

code/go/0chain.net/blobbercore/allocation/file_changer_base.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
77
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
8-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
98
"github.com/0chain/blobber/code/go/0chain.net/core/common"
109
)
1110

@@ -29,7 +28,6 @@ type BaseFileChanger struct {
2928
//client side:
3029
MimeType string `json:"mimetype,omitempty"`
3130
//client side:
32-
Attributes reference.Attributes `json:"attributes,omitempty"`
3331
//client side:
3432
MerkleRoot string `json:"merkle_root,omitempty"`
3533

code/go/0chain.net/blobbercore/allocation/file_changer_update.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ func (nf *UpdateFileChanger) ApplyChange(ctx context.Context, change *Allocation
8787
existingRef.EncryptedKey = nf.EncryptedKey
8888
existingRef.ChunkSize = nf.ChunkSize
8989

90-
if err = existingRef.SetAttributes(&nf.Attributes); err != nil {
91-
return nil, common.NewErrorf("process_update_file_change",
92-
"setting file attributes: %v", err)
93-
}
9490
_, err = rootRef.CalculateHash(ctx, true)
9591
stats.FileUpdated(ctx, existingRef.ID)
9692
return rootRef, err

code/go/0chain.net/blobbercore/allocation/file_changer_upload.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package allocation
33
import (
44
"context"
55
"encoding/json"
6-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
76
"path/filepath"
87
"strings"
98

9+
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
10+
1011
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
1112
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/stats"
1213
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/util"
@@ -96,10 +97,7 @@ func (nf *UploadFileChanger) ApplyChange(ctx context.Context, change *Allocation
9697
newFile.EncryptedKey = nf.EncryptedKey
9798
newFile.ChunkSize = nf.ChunkSize
9899
newFile.HashToBeComputed = true
99-
if err = newFile.SetAttributes(&nf.Attributes); err != nil {
100-
return nil, common.NewErrorf("process_new_file_change",
101-
"setting file attributes: %v", err)
102-
}
100+
103101
dirRef.AddChild(newFile)
104102
if _, err := rootRef.CalculateHash(ctx, true); err != nil {
105103
return nil, err

code/go/0chain.net/blobbercore/allocation/file_changer_upload_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package allocation
22

33
import (
44
"context"
5+
"testing"
6+
"time"
7+
58
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
69
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
710
"github.com/0chain/gosdk/constants"
811
"github.com/stretchr/testify/assert"
9-
"testing"
10-
"time"
1112

1213
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
13-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
1414
"github.com/0chain/blobber/code/go/0chain.net/core/common"
1515
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
1616
"github.com/0chain/gosdk/core/zcncrypto"
@@ -100,7 +100,6 @@ func TestBlobberCore_FileChangerUpload(t *testing.T) {
100100
Filename: "new",
101101
Path: "/",
102102
ActualSize: 2310,
103-
Attributes: reference.Attributes{WhoPaysForReads: common.WhoPaysOwner},
104103
AllocationID: tc.allocationID,
105104
Hash: tc.hash,
106105
Size: 2310,

code/go/0chain.net/blobbercore/allocation/newfilechange.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package allocation
33
import (
44
"context"
55
"encoding/json"
6-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
76
"path/filepath"
87
"strings"
98

9+
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
10+
1011
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
1112
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
1213
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/stats"
@@ -33,8 +34,6 @@ type NewFileChange struct {
3334
//client side:
3435
MimeType string `json:"mimetype,omitempty"`
3536
//client side:
36-
Attributes reference.Attributes `json:"attributes,omitempty"`
37-
//client side:
3837
MerkleRoot string `json:"merkle_root,omitempty"`
3938

4039
//server side: update them by ChangeProcessor
@@ -206,11 +205,6 @@ func (nf *NewFileChange) ApplyChange(ctx context.Context, change *AllocationChan
206205
newFile.ChunkSize = nf.ChunkSize
207206
newFile.HashToBeComputed = true
208207

209-
if err = newFile.SetAttributes(&nf.Attributes); err != nil {
210-
return nil, common.NewErrorf("process_new_file_change",
211-
"setting file attributes: %v", err)
212-
}
213-
214208
dirRef.AddChild(newFile)
215209

216210
if _, err := rootRef.CalculateHash(ctx, true); err != nil {

0 commit comments

Comments
 (0)