55 "encoding/json"
66 "slices"
77
8+ "github.com/golang/geo/s2"
89 "github.com/interuss/dss/pkg/memstore"
10+ dssmodels "github.com/interuss/dss/pkg/models"
911 "github.com/interuss/dss/pkg/raftstore"
1012 "github.com/interuss/dss/pkg/raftstore/consensus"
1113 ridmodels "github.com/interuss/dss/pkg/rid/models"
@@ -30,13 +32,35 @@ const (
3032 DeleteISATransaction raftstore.RequestType = "deleteISATransaction"
3133 InsertISATransaction raftstore.RequestType = "insertISATransaction"
3234 UpdateISATransaction raftstore.RequestType = "updateISATransaction"
35+
36+ getSubscription raftstore.RequestType = "getSubscription"
37+ deleteSubscription raftstore.RequestType = "deleteSubscription"
38+ insertSubscription raftstore.RequestType = "insertSubscription"
39+ updateSubscription raftstore.RequestType = "updateSubscription"
40+ searchSubscriptions raftstore.RequestType = "searchSubscriptions"
41+ searchSubscriptionsByOwner raftstore.RequestType = "searchSubscriptionsByOwner"
42+ updateNotificationIdxsInCells raftstore.RequestType = "updateNotificationIdxsInCells"
43+ maxSubscriptionCountInCellsByOwner raftstore.RequestType = "maxSubscriptionCountInCellsByOwner"
44+ listExpiredSubscriptions raftstore.RequestType = "listExpiredSubscriptions"
45+ countSubscriptions raftstore.RequestType = "countSubscriptions"
46+
47+ DeleteSubscriptionTransaction raftstore.RequestType = "deleteSubscriptionTransaction"
48+ InsertSubscriptionTransaction raftstore.RequestType = "insertSubscriptionTransaction"
49+ UpdateSubscriptionTransaction raftstore.RequestType = "updateSubscriptionTransaction"
3350)
3451
3552var readOnlyRequests = []raftstore.RequestType {
3653 getISA ,
3754 searchISAs ,
3855 listExpiredISAs ,
3956 countISAs ,
57+
58+ getSubscription ,
59+ searchSubscriptions ,
60+ searchSubscriptionsByOwner ,
61+ maxSubscriptionCountInCellsByOwner ,
62+ listExpiredSubscriptions ,
63+ countSubscriptions ,
4064}
4165
4266// repo is a full implementation of rid.repos.Repository for Raft-based storage.
@@ -144,6 +168,83 @@ func (r *repo) Apply(ctx context.Context, proposal consensus.Proposal) (any, err
144168 case UpdateISATransaction :
145169 return r .updateISATransactionApplier (ctx , proposal , mem )
146170
171+ // Subscriptions
172+
173+ case getSubscription :
174+ var id dssmodels.ID
175+ if err := json .Unmarshal (proposal .Value , & id ); err != nil {
176+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , getSubscription )
177+ }
178+ return mem .GetSubscription (ctx , id )
179+
180+ case deleteSubscription :
181+ var sub ridmodels.Subscription
182+ if err := json .Unmarshal (proposal .Value , & sub ); err != nil {
183+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , deleteSubscription )
184+ }
185+ return mem .DeleteSubscription (ctx , & sub )
186+
187+ case insertSubscription :
188+ var sub ridmodels.Subscription
189+ if err := json .Unmarshal (proposal .Value , & sub ); err != nil {
190+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , insertSubscription )
191+ }
192+ return mem .InsertSubscription (ctx , & sub )
193+
194+ case updateSubscription :
195+ var sub ridmodels.Subscription
196+ if err := json .Unmarshal (proposal .Value , & sub ); err != nil {
197+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , updateSubscription )
198+ }
199+ return mem .UpdateSubscription (ctx , & sub )
200+
201+ case searchSubscriptions :
202+ var cells s2.CellUnion
203+ if err := json .Unmarshal (proposal .Value , & cells ); err != nil {
204+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , searchSubscriptions )
205+ }
206+ return mem .SearchSubscriptions (ctx , cells )
207+
208+ case searchSubscriptionsByOwner :
209+ var p searchSubscriptionsByOwnerPayload
210+ if err := json .Unmarshal (proposal .Value , & p ); err != nil {
211+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , searchSubscriptionsByOwner )
212+ }
213+ return mem .SearchSubscriptionsByOwner (ctx , p .Cells , p .Owner )
214+
215+ case updateNotificationIdxsInCells :
216+ var cells s2.CellUnion
217+ if err := json .Unmarshal (proposal .Value , & cells ); err != nil {
218+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , updateNotificationIdxsInCells )
219+ }
220+ return mem .UpdateNotificationIdxsInCells (ctx , cells )
221+
222+ case maxSubscriptionCountInCellsByOwner :
223+ var p maxSubscriptionCountInCellsByOwnerPayload
224+ if err := json .Unmarshal (proposal .Value , & p ); err != nil {
225+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , maxSubscriptionCountInCellsByOwner )
226+ }
227+ return mem .MaxSubscriptionCountInCellsByOwner (ctx , p .Cells , p .Owner )
228+
229+ case listExpiredSubscriptions :
230+ var p listExpiredSubscriptionsPayload
231+ if err := json .Unmarshal (proposal .Value , & p ); err != nil {
232+ return nil , stacktrace .Propagate (err , "failed to unmarshal %s payload" , listExpiredSubscriptions )
233+ }
234+ return mem .ListExpiredSubscriptions (ctx , p .Writer , p .Threshold )
235+
236+ case countSubscriptions :
237+ return mem .CountSubscriptions (ctx )
238+
239+ case DeleteSubscriptionTransaction :
240+ return r .deleteSubscriptionTransactionApplier (ctx , proposal , mem )
241+
242+ case InsertSubscriptionTransaction :
243+ return r .insertSubscriptionTransactionApplier (ctx , proposal , mem )
244+
245+ case UpdateSubscriptionTransaction :
246+ return r .updateSubscriptionTransactionApplier (ctx , proposal , mem )
247+
147248 default :
148249 return nil , stacktrace .NewError ("unknown request type: %q" , proposal .RequestType )
149250 }
0 commit comments