Skip to content

Commit

Permalink
deletion (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohkinozomu authored Nov 19, 2023
1 parent 17a3a96 commit d56c343
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ data:
The hub and agent must reference the same bucket and have appropriate permissions to it.
For instance, in S3, the shortest deletion period is one day. In fuyuu-router, since object storage is used only temporarily, if you want to reduce costs, you can have the hub delete objects by using the `deletion` settings.

```toml
[storage_relay]
objstore_file = "/app/config/objstore.yaml"
threshold_bytes = 128000
deletion = true
```

## limitation

- Currently only HTTP 1.1 is supported. Perhaps HTTP2 is the next roadmap.
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func Start(c AgentConfig) {
}
} else {
if s.commonConfig.Networking.LargeDataPolicy == "storage_relay" && len(httpResponse) > s.commonConfig.StorageRelay.ThresholdBytes {
objectName = s.id + "/" + processChPayload.requestPacket.RequestId + "/response"
objectName = common.ResponseObjectName(s.id, processChPayload.requestPacket.RequestId)
err := s.bucket.Upload(context.Background(), objectName, bytes.NewReader(httpResponse))
if err != nil {
s.logger.Error("Error uploading object to object storage", zap.Error(err))
Expand Down
1 change: 1 addition & 0 deletions internal/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Networking struct {
type StorageRelay struct {
ThresholdBytes int `mapstructure:"threshold_bytes"`
ObjstoreFile string `mapstructure:"objstore_file"`
Deletion bool `mapstructure:"deletion"`
}

type Split struct {
Expand Down
8 changes: 8 additions & 0 deletions internal/common/object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package common

func RequestObjectName(agentID, requstID string) string {
return agentID + "/" + requstID + "/request"
}
func ResponseObjectName(agentID, requstID string) string {
return agentID + "/" + requstID + "/response"
}
12 changes: 11 additions & 1 deletion internal/hub/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (s *server) handleRequest(w http.ResponseWriter, r *http.Request) {

var objectName string
if s.commonConfig.Networking.LargeDataPolicy == "storage_relay" && r.ContentLength > int64(s.commonConfig.StorageRelay.ThresholdBytes) {
objectName = agentID + "/" + uuid + "/request"
objectName = common.RequestObjectName(agentID, uuid)
s.logger.Debug("Uploading object to object storage...")
err := s.bucket.Upload(context.Background(), objectName, r.Body)
if err != nil {
Expand Down Expand Up @@ -463,6 +463,16 @@ func (s *server) handleRequest(w http.ResponseWriter, r *http.Request) {
}
s.bus.DeregisterHandler(uuid)
s.bus.DeregisterTopics(uuid)
if s.commonConfig.Networking.LargeDataPolicy == "storage_relay" && s.commonConfig.StorageRelay.Deletion {
err = s.bucket.Delete(context.Background(), common.RequestObjectName(agentID, uuid))
if err != nil {
s.logger.Error("Error deleting object from object storage", zap.Error(err))
}
err = s.bucket.Delete(context.Background(), common.ResponseObjectName(agentID, uuid))
if err != nil {
s.logger.Error("Error deleting object from object storage", zap.Error(err))
}
}
}

func Start(c HubConfig) {
Expand Down

0 comments on commit d56c343

Please sign in to comment.