Skip to content

Commit bb3ca10

Browse files
authored
Merge pull request #1227 from tigrisdata/main
Beta release
2 parents a08c141 + b7bd383 commit bb3ca10

File tree

7 files changed

+128
-2
lines changed

7 files changed

+128
-2
lines changed

api/server/v1/tx.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
ManagementMethodPrefix = "/tigrisdata.management.v1.Management/"
2929
ObservabilityMethodPrefix = "/tigrisdata.observability.v1.Observability/"
3030
realtimeMethodPrefix = "/tigrisdata.realtime.v1.Realtime/"
31+
searchMethodPrefix = "/tigrisdata.search.v1.Search/"
3132

3233
BeginTransactionMethodName = apiMethodPrefix + "BeginTransaction"
3334
CommitTransactionMethodName = apiMethodPrefix + "CommitTransaction"
@@ -87,7 +88,8 @@ const (
8788
ListUsersMethodName = authMethodPrefix + "ListUsers"
8889

8990
// Billing.
90-
ListInvoicesMethodName = billingMethodPrefix + "ListInvoices"
91+
ListInvoicesMethodName = billingMethodPrefix + "ListInvoices"
92+
BillingGetUsageMethodName = billingMethodPrefix + "GetUsage"
9193

9294
// Cache.
9395
CreateCacheMethodName = cacheMethodPrefix + "CreateCache"
@@ -124,6 +126,20 @@ const (
124126
ReadMessagesMethodName = realtimeMethodPrefix + "ReadMessages"
125127
MessagesMethodName = realtimeMethodPrefix + "Messages"
126128
ListSubscriptionsMethodName = realtimeMethodPrefix + "ListSubscriptions"
129+
130+
// Search
131+
CreateOrUpdateIndexMethodName = searchMethodPrefix + "CreateOrUpdateIndex"
132+
GetIndexMethodName = searchMethodPrefix + "GetIndex"
133+
DeleteIndexMethodName = searchMethodPrefix + "DeleteIndex"
134+
ListIndexesMethodName = searchMethodPrefix + "ListIndexes"
135+
SearchGetMethodName = searchMethodPrefix + "Get"
136+
SearchCreateById = searchMethodPrefix + "CreateById"
137+
SearchCreate = searchMethodPrefix + "Create"
138+
SearchCreateOrReplace = searchMethodPrefix + "CreateOrReplace"
139+
SearchUpdate = searchMethodPrefix + "Update"
140+
SearchDelete = searchMethodPrefix + "Delete"
141+
SearchDeleteByQuery = searchMethodPrefix + "DeleteByQuery"
142+
SearchSearch = searchMethodPrefix + "Search"
127143
)
128144

129145
func IsTxSupported(ctx context.Context) bool {

query/filter/key_builder.go

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package filter
1616

1717
import (
18+
"fmt"
1819
"sort"
1920

2021
"github.com/tigrisdata/tigris/errors"
@@ -24,6 +25,10 @@ import (
2425
"github.com/tigrisdata/tigris/value"
2526
)
2627

28+
var (
29+
ErrKeysEmpty = fmt.Errorf("empty keys")
30+
)
31+
2732
// KeyComposer needs to be implemented to have a custom Compose method with different constraints.
2833
type KeyComposer interface {
2934
Compose(level []*Selector, indexedKeys []*schema.QueryableField, parent LogicalOP) ([]QueryPlan, error)
@@ -203,6 +208,10 @@ func (k *KeyBuilder) Build(filters []Filter, indexedKeys []*schema.QueryableFiel
203208

204209
// PrimaryKey is always a single plan with all the keys
205210
if IndexTypePrimary(k.indexType) {
211+
if len(allKeys) == 0 {
212+
// this is to know in which case error is not triggered but keys are empty.
213+
return nil, ErrKeysEmpty
214+
}
206215
combined := allKeys[0]
207216
for _, plan := range allKeys[1:] {
208217
combined.Keys = append(combined.Keys, plan.Keys...)

server/middleware/authz.go

+45
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ var (
7474

7575
// realtime
7676
api.ReadMessagesMethodName,
77+
78+
// search
79+
api.GetIndexMethodName,
80+
api.ListIndexesMethodName,
81+
api.SearchGetMethodName,
82+
api.SearchSearch,
7783
)
7884

7985
// editor.
@@ -150,6 +156,19 @@ var (
150156
api.ReadMessagesMethodName,
151157
api.MessagesMethodName,
152158
api.ListSubscriptionsMethodName,
159+
160+
// search
161+
api.CreateOrUpdateIndexMethodName,
162+
api.GetIndexMethodName,
163+
api.DeleteIndexMethodName,
164+
api.ListIndexesMethodName,
165+
api.SearchGetMethodName,
166+
api.SearchCreateById,
167+
api.SearchCreate,
168+
api.SearchCreateOrReplace,
169+
api.SearchUpdate,
170+
api.SearchDeleteByQuery,
171+
api.SearchSearch,
153172
)
154173

155174
ownerMethods = container.NewHashSet(
@@ -235,6 +254,19 @@ var (
235254
api.ReadMessagesMethodName,
236255
api.MessagesMethodName,
237256
api.ListSubscriptionsMethodName,
257+
258+
// search
259+
api.CreateOrUpdateIndexMethodName,
260+
api.GetIndexMethodName,
261+
api.DeleteIndexMethodName,
262+
api.ListIndexesMethodName,
263+
api.SearchGetMethodName,
264+
api.SearchCreateById,
265+
api.SearchCreate,
266+
api.SearchCreateOrReplace,
267+
api.SearchUpdate,
268+
api.SearchDeleteByQuery,
269+
api.SearchSearch,
238270
)
239271
clusterAdminMethods = container.NewHashSet(
240272
// db
@@ -314,6 +346,19 @@ var (
314346
api.ReadMessagesMethodName,
315347
api.MessagesMethodName,
316348
api.ListSubscriptionsMethodName,
349+
350+
// search
351+
api.CreateOrUpdateIndexMethodName,
352+
api.GetIndexMethodName,
353+
api.DeleteIndexMethodName,
354+
api.ListIndexesMethodName,
355+
api.SearchGetMethodName,
356+
api.SearchCreateById,
357+
api.SearchCreate,
358+
api.SearchCreateOrReplace,
359+
api.SearchUpdate,
360+
api.SearchDeleteByQuery,
361+
api.SearchSearch,
317362
)
318363
)
319364

server/middleware/authz_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ func TestAuthzOwnerRole(t *testing.T) {
103103
require.True(t, isAuthorizedOperation(api.MessagesMethodName, ownerRoleName))
104104
require.True(t, isAuthorizedOperation(api.ListSubscriptionsMethodName, ownerRoleName))
105105

106+
// search
107+
require.True(t, isAuthorizedOperation(api.CreateOrUpdateIndexMethodName, ownerRoleName))
108+
require.True(t, isAuthorizedOperation(api.GetIndexMethodName, ownerRoleName))
109+
require.True(t, isAuthorizedOperation(api.DeleteIndexMethodName, ownerRoleName))
110+
require.True(t, isAuthorizedOperation(api.ListIndexesMethodName, ownerRoleName))
111+
require.True(t, isAuthorizedOperation(api.SearchGetMethodName, ownerRoleName))
112+
require.True(t, isAuthorizedOperation(api.SearchCreateById, ownerRoleName))
113+
require.True(t, isAuthorizedOperation(api.SearchCreate, ownerRoleName))
114+
require.True(t, isAuthorizedOperation(api.SearchCreateOrReplace, ownerRoleName))
115+
require.True(t, isAuthorizedOperation(api.SearchUpdate, ownerRoleName))
116+
require.True(t, isAuthorizedOperation(api.SearchDeleteByQuery, ownerRoleName))
117+
require.True(t, isAuthorizedOperation(api.SearchSearch, ownerRoleName))
118+
106119
// negative
107120
require.False(t, isAuthorizedOperation(api.VerifyInvitationMethodName, ownerRoleName))
108121
require.False(t, isAuthorizedOperation(api.CreateNamespaceMethodName, ownerRoleName))
@@ -184,6 +197,19 @@ func TestAuthzEditorRole(t *testing.T) {
184197
require.True(t, isAuthorizedOperation(api.MessagesMethodName, editorRoleName))
185198
require.True(t, isAuthorizedOperation(api.ListSubscriptionsMethodName, editorRoleName))
186199

200+
// search
201+
require.True(t, isAuthorizedOperation(api.CreateOrUpdateIndexMethodName, editorRoleName))
202+
require.True(t, isAuthorizedOperation(api.GetIndexMethodName, editorRoleName))
203+
require.True(t, isAuthorizedOperation(api.DeleteIndexMethodName, editorRoleName))
204+
require.True(t, isAuthorizedOperation(api.ListIndexesMethodName, editorRoleName))
205+
require.True(t, isAuthorizedOperation(api.SearchGetMethodName, editorRoleName))
206+
require.True(t, isAuthorizedOperation(api.SearchCreateById, editorRoleName))
207+
require.True(t, isAuthorizedOperation(api.SearchCreate, editorRoleName))
208+
require.True(t, isAuthorizedOperation(api.SearchCreateOrReplace, editorRoleName))
209+
require.True(t, isAuthorizedOperation(api.SearchUpdate, editorRoleName))
210+
require.True(t, isAuthorizedOperation(api.SearchDeleteByQuery, editorRoleName))
211+
require.True(t, isAuthorizedOperation(api.SearchSearch, editorRoleName))
212+
187213
// negative
188214
require.False(t, isAuthorizedOperation(api.ListUsersMethodName, editorRoleName))
189215
require.False(t, isAuthorizedOperation(api.VerifyInvitationMethodName, editorRoleName))
@@ -233,6 +259,12 @@ func TestAuthzReadOnlyRole(t *testing.T) {
233259
// realtime
234260
require.True(t, isAuthorizedOperation(api.ReadMessagesMethodName, readOnlyRoleName))
235261

262+
// search
263+
require.True(t, isAuthorizedOperation(api.GetIndexMethodName, readOnlyRoleName))
264+
require.True(t, isAuthorizedOperation(api.ListIndexesMethodName, readOnlyRoleName))
265+
require.True(t, isAuthorizedOperation(api.SearchGetMethodName, readOnlyRoleName))
266+
require.True(t, isAuthorizedOperation(api.SearchSearch, readOnlyRoleName))
267+
236268
// negative
237269
require.False(t, isAuthorizedOperation(api.BeginTransactionMethodName, readOnlyRoleName))
238270
require.False(t, isAuthorizedOperation(api.CommitTransactionMethodName, readOnlyRoleName))
@@ -269,4 +301,13 @@ func TestAuthzReadOnlyRole(t *testing.T) {
269301
require.False(t, isAuthorizedOperation(api.DeleteGlobalAppKeyMethodName, readOnlyRoleName))
270302
require.False(t, isAuthorizedOperation(api.ListGlobalAppKeysMethodName, readOnlyRoleName))
271303
require.False(t, isAuthorizedOperation(api.RotateGlobalAppKeySecretMethodName, readOnlyRoleName))
304+
305+
// search
306+
require.False(t, isAuthorizedOperation(api.CreateOrUpdateIndexMethodName, readOnlyRoleName))
307+
require.False(t, isAuthorizedOperation(api.DeleteIndexMethodName, readOnlyRoleName))
308+
require.False(t, isAuthorizedOperation(api.SearchCreateById, readOnlyRoleName))
309+
require.False(t, isAuthorizedOperation(api.SearchCreate, readOnlyRoleName))
310+
require.False(t, isAuthorizedOperation(api.SearchCreateOrReplace, readOnlyRoleName))
311+
require.False(t, isAuthorizedOperation(api.SearchUpdate, readOnlyRoleName))
312+
require.False(t, isAuthorizedOperation(api.SearchDeleteByQuery, readOnlyRoleName))
272313
}

server/services/v1/billing/reporter.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ func (r *UsageReporter) pushUsage() error {
102102

103103
for namespaceId, stats := range chunk.Tenants {
104104
nsMeta := r.nsMgr.GetNamespaceMetadata(r.ctx, namespaceId)
105+
if nsMeta == nil {
106+
log.Error().Str("ns", namespaceId).Msgf("namespace metadata cannot be nil")
107+
continue
108+
}
105109
if success := r.setupBillingAccount(nsMeta); !success {
106110
continue
107111
}
@@ -129,7 +133,6 @@ func (r *UsageReporter) pushUsage() error {
129133
// returns true, if billing account already exists or new account was setup
130134
func (r *UsageReporter) setupBillingAccount(nsMeta *metadata.NamespaceMetadata) bool {
131135
if nsMeta == nil {
132-
log.Error().Msgf("namespace metadata cannot be nil")
133136
return false
134137
}
135138

server/services/v1/database/base_runner.go

+5
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ func (runner *BaseQueryRunner) getWriteIterator(ctx context.Context, tx transact
295295
metrics.SetWriteType("non-pkey")
296296
return iterator, nil
297297
}
298+
} else if err == filter.ErrKeysEmpty {
299+
log.Err(err).
300+
Str("collection", collection.Name).
301+
Str("filter", string(reqFilter)).
302+
Msg("not able to build keys")
298303
}
299304

300305
pkIterator, err := reader.ScanTable(collection.EncodedName, false)

server/services/v1/database/query_runner.go

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121

2222
jsoniter "github.com/json-iterator/go"
23+
"github.com/rs/zerolog/log"
2324
api "github.com/tigrisdata/tigris/api/server/v1"
2425
"github.com/tigrisdata/tigris/errors"
2526
"github.com/tigrisdata/tigris/internal"
@@ -601,7 +602,13 @@ func (runner *BaseQueryRunner) buildReaderOptions(req *api.ReadRequest, collecti
601602
if options.plan, err = planner.GeneratePlan(sortPlan, from); err == nil {
602603
// plan can be handled by database index
603604
return options, nil
605+
} else if err == filter.ErrKeysEmpty {
606+
log.Err(err).
607+
Str("collection", collection.Name).
608+
Str("filter", string(req.Filter)).
609+
Msg("not able to build keys")
604610
}
611+
605612
if planner.IsPrefixQueryWithSuffixSort(sortPlan) {
606613
// case when it is a prefix query with suffix sort
607614
options.tablePlan, err = planner.GenerateTablePlan(sortPlan, from)

0 commit comments

Comments
 (0)