Skip to content
Open
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
9 changes: 9 additions & 0 deletions code/go/0chain.net/blobbercore/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func SetupDefaultConfig() {
viper.SetDefault("kv.pebble_cache", 4*1024*1024*1024)
viper.SetDefault("kv.pebble_memtable_size", 256*1024*1024)
viper.SetDefault("kv.pebble_max_open_files", 10000)

viper.SetDefault("0box.sync_notify_url", "")
viper.SetDefault("0box.sync_notify_enabled", false)
}

/*SetupConfig - setup the configuration system */
Expand Down Expand Up @@ -171,6 +174,9 @@ type Config struct {
PebbleCache int64
PebbleMemtableSize int64
PebbleMaxOpenFiles int

SyncNotifyURL string
SyncNotifyEnabled bool
}

/*Configuration of the system */
Expand Down Expand Up @@ -321,6 +327,9 @@ func ReadConfig(deploymentMode int) {
Configuration.PebbleCache = viper.GetInt64("kv.pebble_cache")
Configuration.PebbleMemtableSize = viper.GetInt64("kv.pebble_memtable_size")
Configuration.PebbleMaxOpenFiles = viper.GetInt("kv.pebble_max_open_files")

Configuration.SyncNotifyURL = viper.GetString("0box.sync_notify_url")
Configuration.SyncNotifyEnabled = viper.GetBool("0box.sync_notify_enabled")
}

// StorageSCConfiguration will include all the required sc configs to operate blobber
Expand Down
4 changes: 4 additions & 0 deletions code/go/0chain.net/blobbercore/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,8 @@ func RevokeShare(ctx context.Context, r *http.Request) (interface{}, error) {
return nil, err
}

notifySyncEvent(allocationID, clientID, "share_updated")

resp := map[string]interface{}{
"status": http.StatusNoContent,
"message": "Path successfully removed from allocation",
Expand Down Expand Up @@ -1922,6 +1924,8 @@ func InsertShare(ctx context.Context, r *http.Request) (interface{}, error) {
return nil, common.NewError("share_info_insert", "Unable to save share info")
}

notifySyncEvent(allocationID, clientID, "share_updated")

return map[string]interface{}{"message": "Share info added successfully"}, nil
}

Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/blobbercore/handler/handler_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func WithStatusConnectionForWM(handler common.StatusCodeResponderF) common.Statu
// Save the write marker data
if blobberRes.WriteMarker != nil {
writemarker.SaveMarkerData(allocationID, blobberRes.WriteMarker.WM.Timestamp, blobberRes.WriteMarker.WM.ChainLength)
notifySyncEvent(allocationID, blobberRes.WriteMarker.WM.ClientID, "file_updated")
trie := blobberRes.Trie
if trie != nil && blobberRes.WriteMarker.WM.AllocationRoot != blobberRes.WriteMarker.WM.PreviousAllocationRoot {
_ = trie.DeleteNodes()
Expand Down
47 changes: 47 additions & 0 deletions code/go/0chain.net/blobbercore/handler/sync_notify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package handler

import (
"encoding/json"

"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
. "github.com/0chain/blobber/code/go/0chain.net/core/logging"
"github.com/0chain/blobber/code/go/0chain.net/core/util"
"go.uber.org/zap"
)

func notifySyncEvent(allocationID, clientID, eventType string) {
if !config.Configuration.SyncNotifyEnabled || config.Configuration.SyncNotifyURL == "" {
return
}

Logger.Info("sync_notify_queued",
zap.String("allocation_id", allocationID),
zap.String("client_id", clientID),
zap.String("event_type", eventType),
zap.String("notify_url", config.Configuration.SyncNotifyURL))

payload, err := json.Marshal(map[string]string{
"allocation_id": allocationID,
"client_id": clientID,
"event_type": eventType,
})
if err != nil {
Logger.Error("sync_notify_marshal_failed", zap.Error(err))
return
}

go func() {
resp, err := util.SendPostRequest(config.Configuration.SyncNotifyURL, payload, nil)
if err != nil {
Logger.Error("sync_notify_failed",
zap.String("allocation_id", allocationID),
zap.String("event_type", eventType),
zap.Error(err))
} else {
Logger.Info("sync_notify_sent",
zap.String("allocation_id", allocationID),
zap.String("event_type", eventType),
zap.String("response", string(resp)))
}
}()
}
Loading