Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update allocation add/remove blobber #189

Merged
merged 6 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,23 @@ the presence of the `free_storage` field.
* `otherwise` Update an allocation applying the settings indicated by the
remaining parameters.

If not a `free_storage` update, then tokens will come from those locked. If there are
If not a `free_storage` update, then tokens will come from those locked.
Further we can add a blobber to the allocation,
adding a blobber will allow a blobber to be removed.
An increase in blobber count will increment the parity shards.


| Parameter | Required | Description | Valid Values |
|---------------|----------|--------------------------------------------------------|--------------|
| allocation | yes | allocation id | string |
| expiry | | adjust storage expiration time | duration |
| free_storage | | free storage marker file | string |
| lock | yes* | lock additional tokens in write pool | int |
| set_immutable | | sets allocation so that data can no longer be modified | boolean |
| update_terms | | will update the allocation with the latest blobber terms | boolean |
| size | | adjust allocation size | bytes |
| Parameter | Required | Description | Valid Values |
|---------------|----------|---------------------------------------------------------------------|--------------|
| allocation | yes | allocation id | string |
| expiry | | adjust storage expiration time | duration |
| free_storage | | free storage marker file | string |
| lock | yes* | lock additional tokens in write pool | int |
| set_immutable | | sets allocation so that data can no longer be modified | boolean |
| update_terms | | will update the allocation with the latest blobber terms | boolean |
| size | | adjust allocation size | bytes |
| add_blobber | | add a new blobber to the allocation, required for remove_blobber | string |
| remove_blobber | | remove a blobber from the allocation, requires an add_blobber option | string2 |
`*` only required if free_storage not set.

<details>
Expand Down
34 changes: 32 additions & 2 deletions cmd/updateallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ var updateAllocationCmd = &cobra.Command{
log.Fatal("invalid 'allocation_id' flag: ", err)
}

var addBlobberId, removeBlobberId string
if flags.Changed("add_blobber") {
addBlobberId, err = flags.GetString("add_blobber")
if err != nil {
log.Fatal("invalid 'add_blobber' flag: ", err)
}
if flags.Changed("remove_blobber") {
removeBlobberId, err = flags.GetString("remove_blobber")
if err != nil {
log.Fatal("invalid 'remove_blobber' flag: ", err)
}
}
} else {
if flags.Changed("remove_blobber") {
log.Fatal("Error: cannot remove blobber without adding one")
}
}

if flags.Changed("free_storage") {
lock, freeStorageMarker := processFreeStorageFlags(flags)
if lock < 0 {
Expand Down Expand Up @@ -71,8 +89,16 @@ var updateAllocationCmd = &cobra.Command{

setImmutable, _ := cmd.Flags().GetBool("set_immutable")

txnHash, err := sdk.UpdateAllocation(size,
int64(expiry/time.Second), allocID, lock, setImmutable, updateTerms)
txnHash, err := sdk.UpdateAllocation(
size,
int64(expiry/time.Second),
allocID,
lock,
setImmutable,
updateTerms,
addBlobberId,
removeBlobberId,
)
if err != nil {
log.Fatal("Error updating allocation:", err)
}
Expand All @@ -84,6 +110,10 @@ func init() {
rootCmd.AddCommand(updateAllocationCmd)
updateAllocationCmd.PersistentFlags().String("allocation", "",
"Allocation ID")
updateAllocationCmd.PersistentFlags().String("add_blobber", "",
"ID of blobber to add to the allocation")
updateAllocationCmd.PersistentFlags().String("remove_blobber", "",
"ID of blobber to remove from the allocation")
updateAllocationCmd.PersistentFlags().Float64("lock", 0.0,
"lock write pool with given number of tokens, required")
updateAllocationCmd.PersistentFlags().Int64("size", 0,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.7.7-0.20220404092536-f919a6019908
github.com/0chain/gosdk v1.7.7-0.20220405073506-a55854602967
github.com/icza/bitio v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.1.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ github.com/0chain/gosdk v1.7.7-0.20220404055517-d7ad7bbfbcb2 h1:xUp9fBvye9ZORF1d
github.com/0chain/gosdk v1.7.7-0.20220404055517-d7ad7bbfbcb2/go.mod h1:Cch/iwYKdBMnwcsFm2x9hG4CLYTVChCRFqA1TKRmRXU=
github.com/0chain/gosdk v1.7.7-0.20220404092536-f919a6019908 h1:/Nmxr3vNVg0oCR0BVRNZYUXggj56BBCe9YBsmSK0jGs=
github.com/0chain/gosdk v1.7.7-0.20220404092536-f919a6019908/go.mod h1:Cch/iwYKdBMnwcsFm2x9hG4CLYTVChCRFqA1TKRmRXU=
github.com/0chain/gosdk v1.7.7-0.20220405073506-a55854602967 h1:jc1ZwomrdaKPt0obbEF8Z1S18xXCS+qoa+zZWAUWtkM=
github.com/0chain/gosdk v1.7.7-0.20220405073506-a55854602967/go.mod h1:Cch/iwYKdBMnwcsFm2x9hG4CLYTVChCRFqA1TKRmRXU=
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc=
github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4=
Expand Down