Commit ef98e54f authored by Maxim Ivanov's avatar Maxim Ivanov
Browse files

storage: switch to native UUID type in StorageWrite

parent eff9544a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ require (
	github.com/prometheus/common v0.42.0 // indirect
	github.com/prometheus/procfs v0.10.1 // indirect
	go.uber.org/multierr v1.6.0 // indirect
	golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 // indirect
	golang.org/x/net v0.12.0 // indirect
	golang.org/x/sys v0.10.0 // indirect
	golang.org/x/text v0.11.0 // indirect
+2 −0
Original line number Diff line number Diff line
@@ -610,6 +610,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY=
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
+4 −3
Original line number Diff line number Diff line
@@ -153,12 +153,13 @@ func (s *ApiServer) ReadStorageObjects(ctx context.Context, in *api.ReadStorageO
}

func (s *ApiServer) WriteStorageObjects(ctx context.Context, in *api.WriteStorageObjectsRequest) (*api.StorageObjectAcks, error) {
	userID := ctx.Value(ctxUserIDKey{}).(uuid.UUID).String()
	userID := ctx.Value(ctxUserIDKey{}).(uuid.UUID)
	userIDStr := userID.String()

	// Before hook.
	if fn := s.runtime.BeforeWriteStorageObjects(); fn != nil {
		beforeFn := func(clientIP, clientPort string) error {
			result, err, code := fn(ctx, s.logger, userID, ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxVarsKey{}).(map[string]string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
			result, err, code := fn(ctx, s.logger, userIDStr, ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxVarsKey{}).(map[string]string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
			if err != nil {
				return status.Error(code, err.Error())
			}
@@ -225,7 +226,7 @@ func (s *ApiServer) WriteStorageObjects(ctx context.Context, in *api.WriteStorag
	// After hook.
	if fn := s.runtime.AfterWriteStorageObjects(); fn != nil {
		afterFn := func(clientIP, clientPort string) error {
			return fn(ctx, s.logger, userID, ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxVarsKey{}).(map[string]string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, acks, in)
			return fn(ctx, s.logger, userIDStr, ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxVarsKey{}).(map[string]string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, acks, in)
		}

		// Execute the after function lambda wrapped in a trace for stats measurement.
+2 −2
Original line number Diff line number Diff line
@@ -313,7 +313,7 @@ func (s *ConsoleServer) WriteStorageObject(ctx context.Context, in *console.Writ
	if in.Key == "" {
		return nil, status.Error(codes.InvalidArgument, "Requires a valid key.")
	}
	_, err := uuid.FromString(in.UserId)
	userID, err := uuid.FromString(in.UserId)
	if err != nil {
		return nil, status.Error(codes.InvalidArgument, "Requires a valid user ID.")
	}
@@ -336,7 +336,7 @@ func (s *ConsoleServer) WriteStorageObject(ctx context.Context, in *console.Writ

	acks, code, err := StorageWriteObjects(ctx, s.logger, s.db, s.metrics, s.storageIndex, true, StorageOpWrites{
		&StorageOpWrite{
			OwnerID: in.UserId,
			OwnerID: userID,
			Object: &api.WriteStorageObject{
				Collection:      in.Collection,
				Key:             in.Key,
+6 −4
Original line number Diff line number Diff line
@@ -155,7 +155,8 @@ func importStorageJSON(ctx context.Context, logger *zap.Logger, db *sql.DB, metr
	}

	for i, d := range importedData {
		if _, err := uuid.FromString(d.UserID); err != nil {
		userID, err := uuid.FromString(d.UserID)
		if err != nil {
			return fmt.Errorf("invalid user ID on object #%d", i)
		}

@@ -184,7 +185,7 @@ func importStorageJSON(ctx context.Context, logger *zap.Logger, db *sql.DB, metr
		}

		ops = append(ops, &StorageOpWrite{
			OwnerID: d.UserID,
			OwnerID: userID,
			Object: &api.WriteStorageObject{
				Collection:      d.Collection,
				Key:             d.Key,
@@ -255,7 +256,8 @@ func importStorageCSV(ctx context.Context, logger *zap.Logger, db *sql.DB, metri
			}
		} else {
			user := record[columnIndexes["user_id"]]
			if _, err := uuid.FromString(user); err != nil {
			userID, err := uuid.FromString(user)
			if err != nil {
				return fmt.Errorf("invalid user ID on row #%d", len(ops)+1)
			}
			collection := record[columnIndexes["collection"]]
@@ -283,7 +285,7 @@ func importStorageCSV(ctx context.Context, logger *zap.Logger, db *sql.DB, metri
			}

			ops = append(ops, &StorageOpWrite{
				OwnerID: user,
				OwnerID: userID,
				Object: &api.WriteStorageObject{
					Collection:      collection,
					Key:             key,
Loading