Silvan b5564572bc
feat(eventstore): increase parallel write capabilities (#5940)
This implementation increases parallel write capabilities of the eventstore.
Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and  [06](https://zitadel.com/docs/support/advisory/a10006).
The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`.
If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
2023-10-19 12:19:10 +02:00

60 lines
1.8 KiB
Go

package view
import (
"context"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/query"
usr_view "github.com/zitadel/zitadel/internal/user/repository/view"
usr_view_model "github.com/zitadel/zitadel/internal/user/repository/view/model"
)
const (
tokenTable = "auth.tokens"
)
func (v *View) TokenByIDs(tokenID, userID, instanceID string) (*usr_view_model.TokenView, error) {
return usr_view.TokenByIDs(v.Db, tokenTable, tokenID, userID, instanceID)
}
func (v *View) PutToken(token *usr_view_model.TokenView, event *models.Event) error {
return usr_view.PutToken(v.Db, tokenTable, token)
}
func (v *View) DeleteToken(tokenID, instanceID string, event *models.Event) error {
err := usr_view.DeleteToken(v.Db, tokenTable, tokenID, instanceID)
if err != nil && !errors.IsNotFound(err) {
return err
}
return nil
}
func (v *View) DeleteSessionTokens(agentID, userID, instanceID string, event *models.Event) error {
err := usr_view.DeleteSessionTokens(v.Db, tokenTable, agentID, userID, instanceID)
if err != nil && !errors.IsNotFound(err) {
return err
}
return nil
}
func (v *View) GetLatestState(ctx context.Context) (_ *query.CurrentState, err error) {
q := &query.CurrentStateSearchQueries{
Queries: make([]query.SearchQuery, 2),
}
q.Queries[0], err = query.NewCurrentStatesInstanceIDSearchQuery(authz.GetInstance(ctx).InstanceID())
if err != nil {
return nil, err
}
q.Queries[1], err = query.NewCurrentStatesProjectionSearchQuery(tokenTable)
if err != nil {
return nil, err
}
states, err := v.Query.SearchCurrentStates(ctx, q)
if err != nil || states.SearchResponse.Count == 0 {
return nil, err
}
return states.CurrentStates[0], nil
}