Skip to content

Commit

Permalink
Merge pull request #1219 from tigrisdata/main
Browse files Browse the repository at this point in the history
Beta release
  • Loading branch information
adilansari authored May 19, 2023
2 parents e4b7e74 + 8dccdf3 commit 102c372
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/server/v1/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
HeaderTxOrigin = "Tigris-Tx-Origin"
grpcGatewayPrefix = "Grpc-Gateway-"
HeaderSchemaSignOff = "Tigris-Schema-Sign-Off"
HeaderDisableSearch = "Tigris-Disable-Search"
HeaderSchemaVersion = "Tigris-Schema-Version"
HeaderBypassAuthCache = "Tigris-Bypass-Auth-Cache" // #nosec G101
HeaderReadSearchDataFromStorage = "Tigris-Search-Read-From-Storage"
HeaderServerTiming = "Server-Timing"
Expand Down
4 changes: 4 additions & 0 deletions server/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ func NeedSchemaValidation(ctx context.Context) bool {
return api.GetHeader(ctx, api.HeaderSchemaSignOff) != "true"
}

func DisableSearch(ctx context.Context) bool {
return api.GetHeader(ctx, api.HeaderDisableSearch) == "true"
}

func ReadSearchDataFromStorage(ctx context.Context) bool {
return api.GetHeader(ctx, api.HeaderReadSearchDataFromStorage) == "true"
}
Expand Down
3 changes: 3 additions & 0 deletions server/services/v1/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (b *billingService) getMetronomeId(ctx context.Context, namespaceId string)
log.Warn().Msgf("Could not find namespace, this must not happen with right authn/authz configured")
return uuid.Nil, errors.NotFound("Namespace %s not found", namespaceId)
}
if nsMeta.Accounts == nil {
nsMeta.Accounts = &metadata.AccountIntegrations{}
}

mIdStr, enabled := nsMeta.Accounts.GetMetronomeId()
if !enabled || len(mIdStr) == 0 {
Expand Down
4 changes: 4 additions & 0 deletions server/services/v1/billing/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (r *UsageReporter) pushStorage() error {
events := make([]*StorageEvent, 0, len(tenants))
for _, t := range tenants {
nsMeta := t.GetNamespace().Metadata()
if nsMeta.Accounts == nil {
nsMeta.Accounts = &metadata.AccountIntegrations{}
}

if id, enabled := nsMeta.Accounts.GetMetronomeId(); len(id) == 0 || !enabled {
// user doesn't have metronome integration; skip
continue
Expand Down
10 changes: 10 additions & 0 deletions server/services/v1/database/search_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/tigrisdata/tigris/schema"
"github.com/tigrisdata/tigris/server/config"
"github.com/tigrisdata/tigris/server/metadata"
"github.com/tigrisdata/tigris/server/request"
"github.com/tigrisdata/tigris/server/transaction"
"github.com/tigrisdata/tigris/store/kv"
"github.com/tigrisdata/tigris/store/search"
Expand All @@ -54,6 +55,10 @@ func NewSearchIndexer(searchStore search.Store, tenantMgr *metadata.TenantManage
}

func (i *SearchIndexer) OnPostCommit(ctx context.Context, _ *metadata.Tenant, eventListener kv.EventListener) error {
if request.DisableSearch(ctx) {
return nil
}

for _, event := range eventListener.GetEvents() {
var err error

Expand All @@ -77,11 +82,13 @@ func (i *SearchIndexer) OnPostCommit(ctx context.Context, _ *metadata.Tenant, ev
if searchIndex == nil {
return fmt.Errorf("implicit search index not found")
}

if event.Op == kv.DeleteEvent {
if err = i.searchStore.DeleteDocument(ctx, searchIndex.StoreIndexName(), searchKey); err != nil {
if !search.IsErrNotFound(err) {
return err
}

return nil
}
} else {
Expand All @@ -101,13 +108,16 @@ func (i *SearchIndexer) OnPostCommit(ctx context.Context, _ *metadata.Tenant, ev
}

reader := bytes.NewReader(searchData)

var resp []search.IndexResp

if resp, err = i.searchStore.IndexDocuments(ctx, searchIndex.StoreIndexName(), reader, search.IndexDocumentsOptions{
Action: action,
BatchSize: 1,
}); err != nil {
return err
}

if len(resp) == 1 && !resp[0].Success {
return search.NewSearchError(resp[0].Code, search.ErrCodeUnhandled, resp[0].Error)
}
Expand Down

0 comments on commit 102c372

Please sign in to comment.