Skip to content

Commit

Permalink
replace uuid with ulid (#251)
Browse files Browse the repository at this point in the history
* replace uuid with ulid.
  • Loading branch information
sudiptob2 authored Oct 3, 2024
1 parent 457704f commit 3bda40d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
5 changes: 3 additions & 2 deletions internal/database/repository/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"fmt"
"time"

"github.com/oklog/ulid/v2"

"github.com/G-Research/yunikorn-history-server/internal/model"
"github.com/G-Research/yunikorn-history-server/internal/util"

"github.com/G-Research/yunikorn-history-server/internal/database/sql"

"github.com/apache/yunikorn-core/pkg/webservice/dao"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
)

Expand Down Expand Up @@ -80,7 +81,7 @@ func (s *PostgresRepository) UpsertApplications(ctx context.Context, apps []*dao
}
_, err = s.dbpool.Exec(ctx, upsertSQL,
pgx.NamedArgs{
"id": uuid.NewString(),
"id": ulid.Make().String(),
"app_id": a.ApplicationID,
"used_resource": a.UsedResource,
"max_used_resource": a.MaxUsedResource,
Expand Down
6 changes: 3 additions & 3 deletions internal/database/repository/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"

"github.com/apache/yunikorn-core/pkg/webservice/dao"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/oklog/ulid/v2"
)

func (s *PostgresRepository) UpdateHistory(
Expand All @@ -23,7 +23,7 @@ func (s *PostgresRepository) UpdateHistory(
for _, app := range apps {
_, err := s.dbpool.Exec(ctx, appSQL,
pgx.NamedArgs{
"id": uuid.NewString(),
"id": ulid.Make().String(),
"total_number": app.TotalApplications,
"timestamp": app.Timestamp,
})
Expand All @@ -34,7 +34,7 @@ func (s *PostgresRepository) UpdateHistory(
for _, container := range containers {
_, err := s.dbpool.Exec(ctx, containerSQL,
pgx.NamedArgs{
"id": uuid.NewString(),
"id": ulid.Make().String(),
"total_number": container.TotalContainers,
"timestamp": container.Timestamp,
})
Expand Down
5 changes: 2 additions & 3 deletions internal/database/repository/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"github.com/apache/yunikorn-core/pkg/webservice/dao"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/oklog/ulid/v2"
)
Expand All @@ -29,7 +28,7 @@ func (s *PostgresRepository) UpsertNodes(ctx context.Context, nodes []*dao.NodeD
for _, n := range nodes {
_, err := s.dbpool.Exec(ctx, upsertSQL,
pgx.NamedArgs{
"id": uuid.NewString(),
"id": ulid.Make().String(),
"node_id": n.NodeID,
"partition": partition,
"host_name": n.HostName,
Expand Down Expand Up @@ -63,7 +62,7 @@ func (s *PostgresRepository) InsertNodeUtilizations(
for _, nu := range nus {
_, err := s.dbpool.Exec(ctx, insertSQL,
pgx.NamedArgs{
"id": ulid.Make(),
"id": ulid.Make().String(),
"cluster_id": nu.ClusterID,
"partition": nu.Partition,
"nodes_util_list": nu.NodesUtilList,
Expand Down
4 changes: 2 additions & 2 deletions internal/database/repository/partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"

"github.com/apache/yunikorn-core/pkg/webservice/dao"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/oklog/ulid/v2"
)

func (s *PostgresRepository) UpsertPartitions(ctx context.Context, partitions []*dao.PartitionInfo) error {
Expand Down Expand Up @@ -35,7 +35,7 @@ func (s *PostgresRepository) UpsertPartitions(ctx context.Context, partitions []
for _, p := range partitions {
_, err := s.dbpool.Exec(ctx, upsertSQL,
pgx.NamedArgs{
"id": uuid.NewString(),
"id": ulid.Make().String(),
"cluster_id": p.ClusterID,
"name": p.Name,
"capacity": p.Capacity.Capacity,
Expand Down
4 changes: 2 additions & 2 deletions internal/database/repository/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"time"

"github.com/apache/yunikorn-core/pkg/webservice/dao"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/oklog/ulid/v2"

"github.com/G-Research/yunikorn-history-server/internal/model"
"github.com/G-Research/yunikorn-history-server/internal/util"
Expand Down Expand Up @@ -59,7 +59,7 @@ func (s *PostgresRepository) UpsertQueues(ctx context.Context, queues []*dao.Par
}
_, err = s.dbpool.Exec(ctx, upsertSQL,
pgx.NamedArgs{
"id": uuid.NewString(),
"id": ulid.Make().String(),
"parent_id": parentId,
"queue_name": q.QueueName,
"status": q.Status,
Expand Down
10 changes: 5 additions & 5 deletions migrations/20240628155246_init-tables.up.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Create partitions table
CREATE TABLE partitions(
id UUID,
id TEXT,
cluster_id TEXT NOT NULL,
name TEXT NOT NULL,
capacity JSONB,
Expand All @@ -18,7 +18,7 @@ CREATE TABLE partitions(

-- Create applications table
CREATE TABLE applications(
id UUID,
id TEXT,
app_id TEXT NOT NULL,
used_resource JSONB,
max_used_resource JSONB,
Expand Down Expand Up @@ -80,7 +80,7 @@ CREATE UNIQUE INDEX idx_partition_queue_name ON queues (partition, queue_name);

-- Create nodes table
CREATE TABLE nodes(
id UUID,
id TEXT,
node_id TEXT NOT NULL,
partition TEXT NOT NULL,
host_name TEXT NOT NULL,
Expand All @@ -102,7 +102,7 @@ CREATE TABLE nodes(

-- Create partition_nodes_util table
CREATE TABLE partition_nodes_util(
id UUID,
id TEXT,
cluster_id TEXT NOT NULL,
partition TEXT NOT NULL,
nodes_util_list JSONB,
Expand All @@ -118,7 +118,7 @@ CREATE TYPE history_type AS ENUM ('container', 'application');

-- Create history table
CREATE TABLE history(
id UUID,
id TEXT,
history_type history_type NOT NULL,
total_number BIGINT NOT NULL,
timestamp BIGINT NOT NULL,
Expand Down

0 comments on commit 3bda40d

Please sign in to comment.