Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally register archival category #3867

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions service/history/queueFactoryBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"go.temporal.io/server/service/history/configs"
"go.temporal.io/server/service/history/queues"
"go.temporal.io/server/service/history/shard"
"go.temporal.io/server/service/history/tasks"
wcache "go.temporal.io/server/service/history/workflow/cache"
)

Expand Down Expand Up @@ -136,8 +137,13 @@ func getQueueFactories(
queueFactorySet.TimerQueueFactory,
queueFactorySet.VisibilityQueueFactory,
}
c := tasks.CategoryArchival
// this will only affect tests because this method is only called once in production,
// but it may be called many times across test runs, which would leave the archival queue as a dangling category
tasks.RemoveCategory(c.ID())
if archivalMetadata.GetHistoryConfig().StaticClusterState() == archiver.ArchivalEnabled || archivalMetadata.GetVisibilityConfig().StaticClusterState() == archiver.ArchivalEnabled {
factories = append(factories, queueFactorySet.ArchivalQueueFactory)
tasks.NewCategory(c.ID(), c.Type(), c.Name())
}
return factories
}
Expand Down
6 changes: 5 additions & 1 deletion service/history/queue_factory_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/fx"

Expand All @@ -45,6 +46,7 @@ import (
"go.temporal.io/server/common/sdk"
"go.temporal.io/server/service/history/archival"
"go.temporal.io/server/service/history/configs"
"go.temporal.io/server/service/history/tasks"
"go.temporal.io/server/service/history/workflow"
"go.temporal.io/server/service/worker/archiver"
)
Expand Down Expand Up @@ -93,7 +95,7 @@ type moduleTestCase struct {

// Run runs the test case.
func (c *moduleTestCase) Run(t *testing.T) {
t.Parallel()

controller := gomock.NewController(t)
dependencies := getModuleDependencies(controller, c)
var factories []QueueFactory
Expand Down Expand Up @@ -135,8 +137,10 @@ func (c *moduleTestCase) Run(t *testing.T) {
require.NotNil(t, viq)
if c.ExpectArchivalQueue {
require.NotNil(t, aq)
assert.Contains(t, tasks.GetCategories(), tasks.CategoryIDArchival)
} else {
require.Nil(t, aq)
assert.NotContains(t, tasks.GetCategories(), tasks.CategoryIDArchival)
}
}

Expand Down
8 changes: 8 additions & 0 deletions service/history/tasks/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ func GetCategories() map[int32]Category {
return maps.Clone(categories.m)
}

// RemoveCategory removes a registered Category.
// This should only be used for testing.
func RemoveCategory(id int32) {
categories.Lock()
defer categories.Unlock()
delete(categories.m, id)
}

// GetCategoryByID returns a registered Category with the same ID
func GetCategoryByID(id int32) (Category, bool) {
categories.RLock()
Expand Down