You could try to adapt this example 118, but I think the proper approach would be to create or read the indices either in the sampler or the Dataset without the need to manipulate it. This shared array approach sounds more like a hack, so what exactly are you changing in the dataset?
If you are using two indices, one for the data sample and another one for the coordinates, would it be possible to create a list of indices of these pairs and increase the length of the dataset to sample from them?