Skip to content

Conversation

@ankikuma
Copy link
Contributor

This POC attempts to double the number of shards of an existing index.

@elasticsearchmachine elasticsearchmachine added serverless-linked Added by automation, don't add manually v9.0.0 labels Jan 28, 2025
@ankikuma
Copy link
Contributor Author

I have not tested this out yet. The main approach is in MetadataAutoshardIndexService.java

@ankikuma ankikuma added the WIP label Jan 28, 2025
Copy link
Contributor

@bcully bcully left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this operation isn't an actual safe reshard yet - no data is relocated or anything. But it might be nice to include a starter test that sets up, say, a single shard index, then reshards it and then submits some indexing and search operations and confirms that they are handled correctly (all data indexed and returned on search) and that the data spans shards?

}

public String index() {
return index;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we generally refer to indices by name internally? I had imagined that they would come in that way at the client side because that's the client-friendly way to refer to one, but that we might translate them to something less ambiguous like the uuid internally so we wouldn't have to think about things like ABA races.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I have seen, we use the name and the Index data structure quite interchangeably in the code. Not sure if there are some guidelines around which of the two to pass around internally.

}

public String cause() {
return cause;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is some standard request component?

Copy link
Contributor Author

@ankikuma ankikuma Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, I think a request can contain whatever we think we need to put in the request. I was modeling this after CreateIndexClusterStateUpdateRequest and a cause field seemed useful for a re-sharding request. But really this is as bare bones a request as possible for re-sharding, we might need to add more stuff to this.

waitForActiveShardsTimeout,
delegate.map(shardsAcknowledged -> {
if (shardsAcknowledged == false) {
logger.debug(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good for this to be higher than debug, it's I guess not going to be spammy.

})
);
} else {
logger.trace("index creation not acknowledged for [{}]", request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this happen? Is it an error condition?


Settings.Builder settingsBuilder = Settings.builder().put(sourceMetadata.getSettings());
settingsBuilder.remove(IndexMetadata.SETTING_NUMBER_OF_SHARDS);
settingsBuilder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, sourceNumShards * 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it might be for later, but seems like it might be nice for the new number of shards to be a request parameter.

@ankikuma ankikuma removed the serverless-linked Added by automation, don't add manually label Feb 7, 2025
@ankikuma ankikuma marked this pull request as ready for review February 25, 2025 20:33
@ankikuma ankikuma changed the title POC [Autoshard] Add shards to existing Index Resharding - Adding shards to an existing index Mar 4, 2025
Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good though I am in doubt about the routing-num-shards part.

settings = Settings.builder().put(settings).put(SETTING_NUMBER_OF_SHARDS, shardCount).build();
var newPrimaryTerms = new long[shardCount];
System.arraycopy(primaryTerms, 0, newPrimaryTerms, 0, this.primaryTerms.length);
primaryTerms = newPrimaryTerms;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should fill the remaining part of the primary terms array with UNASSIGNED_PRIMARY_TERM, just like in initializePrimaryTerms and leave it to the client to fill those in.

var newPrimaryTerms = new long[shardCount];
System.arraycopy(primaryTerms, 0, newPrimaryTerms, 0, this.primaryTerms.length);
primaryTerms = newPrimaryTerms;
routingNumShards = shardCount;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this bit. I think we discussed it previously but do not recall the conclusion. When I look at MetadataCreateIndexService.calculateNumRoutingShards, it looks somewhat different to this.

}
} else if (reason.equals(Reason.RESHARD_ADDED)
&& out.getTransportVersion().before(TransportVersions.UNASSIGENEDINFO_RESHARD_ADDED)) {
out.writeByte((byte) Reason.FORCED_EMPTY_PRIMARY.ordinal());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we assert false here? I think we want this to never happen, i.e., do resharding in mixed clusters. I'd probably also prefer throwing over sending a more or less random reason here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure. But then should we also assert in the Unassigned constructor ?

Copy link
Contributor

@Tim-Brooks Tim-Brooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Tim-Brooks Tim-Brooks added :Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. >non-issue and removed WIP labels Mar 5, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Indexing Meta label for Distributed Indexing team label Mar 5, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-indexing (Team:Distributed Indexing)

@Tim-Brooks Tim-Brooks merged commit 473c4da into elastic:main Mar 6, 2025
17 checks passed
georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Mar 11, 2025
This POC attempts to double the number of shards of an existing index.
costin pushed a commit to costin/elasticsearch that referenced this pull request Mar 15, 2025
This POC attempts to double the number of shards of an existing index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. >non-issue serverless-linked Added by automation, don't add manually Team:Distributed Indexing Meta label for Distributed Indexing team v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants