-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimpl.go
More file actions
186 lines (152 loc) · 6.52 KB
/
impl.go
File metadata and controls
186 lines (152 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package proxy
import (
"context"
"fmt"
"time"
"github.com/google/uuid"
"github.com/brunoscheufler/gopherconuk25/constants"
"github.com/brunoscheufler/gopherconuk25/store"
"github.com/brunoscheufler/gopherconuk25/telemetry"
)
func (p *DataProxy) init() error {
legacyStore, err := store.NewNoteStore(store.DefaultStoreOptions(constants.LegacyNoteStore, p.logger))
if err != nil {
return fmt.Errorf("failed to create note store: %w", err)
}
p.legacyNoteStore = legacyStore
return nil
}
// ListNotes lists notes with account details consideration
func (p *DataProxy) ListNotes(ctx context.Context, accountDetails AccountDetails) ([]uuid.UUID, error) {
p.lockWithContentionTracking("ListNotes")
defer p.mu.Unlock()
// TODO: Use accountDetails to conditionally run migration logic and shard routing
// For now, this is a placeholder that maintains existing behavior
_ = accountDetails
start := time.Now()
result, err := p.legacyNoteStore.ListNotes(ctx, accountDetails.AccountID)
status := telemetry.DataStoreAccessStatusSuccess
if err != nil {
status = telemetry.DataStoreAccessStatusError
}
// Track metrics, ignoring errors to avoid disrupting main operation
_ = p.statsCollector.TrackDataStoreAccess("ListNotes", time.Since(start), constants.LegacyNoteStore, status)
return result, err
}
// GetNote gets a note with account details consideration
func (p *DataProxy) GetNote(ctx context.Context, accountDetails AccountDetails, noteID uuid.UUID) (*store.Note, error) {
p.lockWithContentionTracking("GetNote")
defer p.mu.Unlock()
// TODO: Use accountDetails to conditionally run migration logic and shard routing
// For now, this is a placeholder that maintains existing behavior
_ = accountDetails
start := time.Now()
result, err := p.legacyNoteStore.GetNote(ctx, accountDetails.AccountID, noteID)
status := telemetry.DataStoreAccessStatusSuccess
if err != nil {
status = telemetry.DataStoreAccessStatusError
}
// Track metrics, ignoring errors to avoid disrupting main operation
_ = p.statsCollector.TrackDataStoreAccess("GetNote", time.Since(start), constants.LegacyNoteStore, status)
return result, err
}
// CreateNote creates a note with account details consideration
func (p *DataProxy) CreateNote(ctx context.Context, accountDetails AccountDetails, note store.Note) error {
p.lockWithContentionTracking("CreateNote")
defer p.mu.Unlock()
// TODO: Use accountDetails to conditionally run migration logic and shard routing
// For now, this is a placeholder that maintains existing behavior
_ = accountDetails
start := time.Now()
err := p.legacyNoteStore.CreateNote(ctx, accountDetails.AccountID, note)
status := telemetry.DataStoreAccessStatusSuccess
if err != nil {
status = telemetry.DataStoreAccessStatusError
}
// Track metrics, ignoring errors to avoid disrupting main operation
_ = p.statsCollector.TrackDataStoreAccess("CreateNote", time.Since(start), constants.LegacyNoteStore, status)
// Report new total count
totalCount, err := p.legacyNoteStore.GetTotalNotes(ctx)
if err != nil {
return fmt.Errorf("could not retrieve total note count: %w", err)
}
p.statsCollector.TrackNoteCount(constants.LegacyNoteStore, totalCount)
return err
}
// UpdateNote updates a note with account details consideration
func (p *DataProxy) UpdateNote(ctx context.Context, accountDetails AccountDetails, note store.Note) error {
p.lockWithContentionTracking("UpdateNote")
defer p.mu.Unlock()
// TODO: Use accountDetails to conditionally run migration logic and shard routing
// For now, this is a placeholder that maintains existing behavior
_ = accountDetails
start := time.Now()
err := p.legacyNoteStore.UpdateNote(ctx, accountDetails.AccountID, note)
status := telemetry.DataStoreAccessStatusSuccess
if err != nil {
status = telemetry.DataStoreAccessStatusError
}
// Track metrics, ignoring errors to avoid disrupting main operation
_ = p.statsCollector.TrackDataStoreAccess("UpdateNote", time.Since(start), constants.LegacyNoteStore, status)
return err
}
// DeleteNote deletes a note with account details consideration
func (p *DataProxy) DeleteNote(ctx context.Context, accountDetails AccountDetails, note store.Note) error {
p.lockWithContentionTracking("DeleteNote")
defer p.mu.Unlock()
// TODO: Use accountDetails to conditionally run migration logic and shard routing
// For now, this is a placeholder that maintains existing behavior
_ = accountDetails
start := time.Now()
err := p.legacyNoteStore.DeleteNote(ctx, accountDetails.AccountID, note)
status := telemetry.DataStoreAccessStatusSuccess
if err != nil {
status = telemetry.DataStoreAccessStatusError
}
// Track metrics, ignoring errors to avoid disrupting main operation
_ = p.statsCollector.TrackDataStoreAccess("DeleteNote", time.Since(start), constants.LegacyNoteStore, status)
// Report new total count
totalCount, err := p.legacyNoteStore.GetTotalNotes(ctx)
if err != nil {
return fmt.Errorf("could not retrieve total note count: %w", err)
}
p.statsCollector.TrackNoteCount(constants.LegacyNoteStore, totalCount)
return err
}
// CountNotes counts notes with account details consideration
func (p *DataProxy) CountNotes(ctx context.Context, accountDetails AccountDetails) (int, error) {
p.lockWithContentionTracking("CountNotes")
defer p.mu.Unlock()
// TODO: Use accountDetails to conditionally run migration logic and shard routing
// For now, this is a placeholder that maintains existing behavior
_ = accountDetails
return p.legacyNoteStore.CountNotes(ctx, accountDetails.AccountID)
}
// GetTotalNotes implements NoteStore interface with locking
func (p *DataProxy) GetTotalNotes(ctx context.Context) (int, error) {
p.lockWithContentionTracking("GetTotalNotes")
defer p.mu.Unlock()
totalCount, err := p.legacyNoteStore.GetTotalNotes(ctx)
if err != nil {
return 0, fmt.Errorf("could not retrieve total count: %w", err)
}
p.statsCollector.TrackNoteCount(constants.LegacyNoteStore, totalCount)
return totalCount, nil
}
// HealthCheck implements NoteStore interface with locking
func (p *DataProxy) HealthCheck(ctx context.Context) error {
p.lockWithContentionTracking("HealthCheck")
defer p.mu.Unlock()
return p.legacyNoteStore.HealthCheck(ctx)
}
// Ready RPC method for readiness checks
func (p *DataProxy) Ready(ctx context.Context) error {
return p.HealthCheck(ctx)
}
// lockWithContentionTracking attempts to acquire the lock
func (p *DataProxy) lockWithContentionTracking(operation string) {
for !p.mu.TryLock() {
_ = p.statsCollector.TrackProxyAccess(operation, 0, p.proxyID, telemetry.ProxyAccessStatusContention)
time.Sleep(5 * time.Millisecond)
}
}