@@ -5,44 +5,143 @@ import (
55 "time"
66
77 "github.com/golang/geo/s2"
8- dsserr "github.com/interuss/dss/pkg/errors"
98 dssmodels "github.com/interuss/dss/pkg/models"
109 scdmodels "github.com/interuss/dss/pkg/scd/models"
1110 "github.com/interuss/stacktrace"
1211)
1312
14- func (r * repo ) SearchSubscriptions (_ context.Context , v4d * dssmodels.Volume4D ) ([]* scdmodels.Subscription , error ) {
15- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "SearchSubscriptions not implemented for raftstore" )
13+ func (r * repo ) SearchSubscriptions (ctx context.Context , v4d * dssmodels.Volume4D ) ([]* scdmodels.Subscription , error ) {
14+ result , err := r .consensus .ProposeValue (ctx , storeID , string (searchSubscriptions ), v4d , true )
15+ if err != nil {
16+ return nil , stacktrace .Propagate (err , "failed to propose searchSubscriptions" )
17+ }
18+
19+ if result == nil {
20+ return nil , nil
21+ }
22+
23+ subs , ok := result .([]* scdmodels.Subscription )
24+ if ! ok {
25+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
26+ }
27+
28+ return subs , nil
1629}
1730
18- func (r * repo ) GetSubscription (_ context.Context , id dssmodels.ID ) (* scdmodels.Subscription , error ) {
19- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "GetSubscription not implemented for raftstore" )
31+ func (r * repo ) GetSubscription (ctx context.Context , id dssmodels.ID ) (* scdmodels.Subscription , error ) {
32+ result , err := r .consensus .ProposeValue (ctx , storeID , string (getSubscription ), id , true )
33+ if err != nil {
34+ return nil , stacktrace .Propagate (err , "failed to propose getSubscription" )
35+ }
36+
37+ if result == nil {
38+ return nil , nil
39+ }
40+
41+ sub , ok := result .(* scdmodels.Subscription )
42+ if ! ok {
43+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
44+ }
45+
46+ return sub , nil
2047}
2148
22- func (r * repo ) UpsertSubscription (_ context.Context , sub * scdmodels.Subscription ) (* scdmodels.Subscription , error ) {
23- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "UpsertSubscription not implemented for raftstore" )
49+ func (r * repo ) UpsertSubscription (ctx context.Context , sub * scdmodels.Subscription ) (* scdmodels.Subscription , error ) {
50+ result , err := r .consensus .ProposeValue (ctx , storeID , string (upsertSubscription ), sub , false )
51+ if err != nil {
52+ return nil , stacktrace .Propagate (err , "failed to propose upsertSubscription" )
53+ }
54+
55+ if result == nil {
56+ return nil , nil
57+ }
58+
59+ upserted , ok := result .(* scdmodels.Subscription )
60+ if ! ok {
61+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
62+ }
63+
64+ return upserted , nil
2465}
2566
26- func (r * repo ) DeleteSubscription (_ context.Context , id dssmodels.ID ) error {
27- return stacktrace .NewErrorWithCode (dsserr .NotImplemented , "DeleteSubscription not implemented for raftstore" )
67+ func (r * repo ) DeleteSubscription (ctx context.Context , id dssmodels.ID ) error {
68+ _ , err := r .consensus .ProposeValue (ctx , storeID , string (deleteSubscription ), id , false )
69+ return err
2870}
2971
30- func (r * repo ) IncrementNotificationIndicesForOperationalIntents (_ context.Context , v4d * dssmodels.Volume4D ) ([]* scdmodels.Subscription , error ) {
31- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "IncrementNotificationIndicesForOperationalIntents not implemented for raftstore" )
72+ func (r * repo ) IncrementNotificationIndicesForOperationalIntents (ctx context.Context , v4d * dssmodels.Volume4D ) ([]* scdmodels.Subscription , error ) {
73+ result , err := r .consensus .ProposeValue (ctx , storeID , string (incrementNotificationForOIs ), v4d , false )
74+ if err != nil {
75+ return nil , stacktrace .Propagate (err , "failed to propose incrementNotificationForOIs" )
76+ }
77+
78+ if result == nil {
79+ return nil , nil
80+ }
81+
82+ subs , ok := result .([]* scdmodels.Subscription )
83+ if ! ok {
84+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
85+ }
86+
87+ return subs , nil
3288}
3389
34- func (r * repo ) IncrementNotificationIndicesForConstraints (_ context.Context , v4d * dssmodels.Volume4D ) ([]* scdmodels.Subscription , error ) {
35- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "IncrementNotificationIndicesForConstraints not implemented for raftstore" )
90+ func (r * repo ) IncrementNotificationIndicesForConstraints (ctx context.Context , v4d * dssmodels.Volume4D ) ([]* scdmodels.Subscription , error ) {
91+ result , err := r .consensus .ProposeValue (ctx , storeID , string (incrementNotificationForConstraints ), v4d , false )
92+ if err != nil {
93+ return nil , stacktrace .Propagate (err , "failed to propose incrementNotificationForConstraints" )
94+ }
95+
96+ if result == nil {
97+ return nil , nil
98+ }
99+
100+ subs , ok := result .([]* scdmodels.Subscription )
101+ if ! ok {
102+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
103+ }
104+
105+ return subs , nil
36106}
37107
38- func (r * repo ) LockSubscriptionsOnCells (_ context.Context , cells s2.CellUnion , subscriptionIds []dssmodels.ID , startTime * time.Time , endTime * time.Time ) error {
39- return stacktrace .NewErrorWithCode (dsserr .NotImplemented , "LockSubscriptionsOnCells not implemented for raftstore" )
108+ func (r * repo ) LockSubscriptionsOnCells (_ context.Context , _ s2.CellUnion , _ []dssmodels.ID , _ * time.Time , _ * time.Time ) error {
109+ // for the raftstore, LockSubscriptionsOnCells is a no-op
110+ return nil
40111}
41112
42- func (r * repo ) ListExpiredSubscriptions (_ context.Context , threshold time.Time ) ([]* scdmodels.Subscription , error ) {
43- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "ListExpiredSubscriptions not implemented for raftstore" )
113+ func (r * repo ) ListExpiredSubscriptions (ctx context.Context , threshold time.Time ) ([]* scdmodels.Subscription , error ) {
114+ result , err := r .consensus .ProposeValue (ctx , storeID , string (listExpiredSubscriptions ), threshold , true )
115+ if err != nil {
116+ return nil , stacktrace .Propagate (err , "failed to propose listExpiredSubscriptions" )
117+ }
118+
119+ if result == nil {
120+ return nil , nil
121+ }
122+
123+ subs , ok := result .([]* scdmodels.Subscription )
124+ if ! ok {
125+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
126+ }
127+
128+ return subs , nil
44129}
45130
46- func (r * repo ) CountSubscriptions (_ context.Context ) (int64 , error ) {
47- return 0 , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "CountSubscriptions not implemented for raftstore" )
131+ func (r * repo ) CountSubscriptions (ctx context.Context ) (int64 , error ) {
132+ result , err := r .consensus .ProposeValue (ctx , storeID , string (countSubscriptions ), nil , true )
133+ if err != nil {
134+ return 0 , stacktrace .Propagate (err , "failed to propose countSubscriptions" )
135+ }
136+
137+ if result == nil {
138+ return 0 , nil
139+ }
140+
141+ count , ok := result .(int64 )
142+ if ! ok {
143+ return 0 , stacktrace .NewError ("invalid result type: %T" , result )
144+ }
145+
146+ return count , nil
48147}
0 commit comments