···6161 // IndexDir is a directory that holds *.zoekt index files.
6262 IndexDir string
63636464+ // ShardPrefixOverride sets the prefix for shards name
6565+ ShardPrefixOverride string
6666+6467 // SizeMax is the maximum file size
6568 SizeMax int
6669···182185 fs.IntVar(&o.ShardMax, "shard_limit", x.ShardMax, "maximum corpus size for a shard")
183186 fs.IntVar(&o.Parallelism, "parallelism", x.Parallelism, "maximum number of parallel indexing processes.")
184187 fs.StringVar(&o.IndexDir, "index", x.IndexDir, "directory for search indices")
188188+ fs.StringVar(&o.ShardPrefixOverride, "shard_prefix_override", x.ShardPrefixOverride, "prefix for shard name")
185189 fs.BoolVar(&o.CTagsMustSucceed, "require_ctags", x.CTagsMustSucceed, "If set, ctags calls must succeed.")
186190 fs.Var(largeFilesFlag{o}, "large_file", "A glob pattern where matching files are to be index regardless of their size. You can add multiple patterns by setting this more than once.")
187191···214218 args = append(args, "-index", o.IndexDir)
215219 }
216220221221+ if o.ShardPrefixOverride != "" {
222222+ args = append(args, "-shard_prefix_override", o.ShardPrefixOverride)
223223+ }
224224+217225 if o.CTagsMustSucceed {
218226 args = append(args, "-require_ctags")
219227 }
···334342}
335343336344func (o *Options) shardNameVersion(version, n int) string {
337337- var prefix string
345345+ prefix := o.ShardPrefixOverride // ShardPrefixOverride takes precedence to support custom shard naming strategies
338346339339- // Sourcegraph specific: We use IDs in shard names on multi-tenant
340340- // instances to prevent conflicts.
341341- if tenant.UseIDBasedShardNames() {
342342- prefix = fmt.Sprintf("%09d_%09d", o.RepositoryDescription.TenantID, o.RepositoryDescription.ID)
343343- } else {
344344- prefix = o.RepositoryDescription.Name
347347+ if prefix == "" {
348348+ // Sourcegraph specific: We use IDs in shard names on multi-tenant
349349+ // instances to prevent conflicts.
350350+ if tenant.UseIDBasedShardNames() {
351351+ prefix = fmt.Sprintf("%09d_%09d", o.RepositoryDescription.TenantID, o.RepositoryDescription.ID)
352352+ } else {
353353+ prefix = o.RepositoryDescription.Name
354354+ }
345355 }
346356347357 return shardName(o.IndexDir, prefix, version, n)