service-fabric-indexing icon indicating copy to clipboard operation
service-fabric-indexing copied to clipboard

[NEW FEATURE REQUEST] Generate index for old data

Open heavenwing opened this issue 6 years ago • 5 comments

After add index into a Dictionary with old data, this index can generate indexed data for old data. Or can rebuild indexed data for whole data include old data and new data.

heavenwing avatar Jan 20 '19 13:01 heavenwing

What is the correct approach to add an index on old data when migrating to service-fabric-indexing? The old data on my collections are not indexed.

jfalameda avatar Mar 04 '20 16:03 jfalameda

Yeah ... this was always a gap. In my mind, there's two ways to do this:

[1] Add an API to IReliableIndexedDictionary like RebuildIndexAsync(), which will enumerate the values in the dictionary and add/update to the indexes. [2] In a single transaction: remove the value from the IReliableDictionary, add the value to the IReliableIndexedDictionary, commit. Do this for all values in the dictionary.

Service Fabric has limitations on the size of changes (in bytes) within a single transaction. So both approaches above will likely need to be done across multiple transactions. That has consistency considerations.

Alternatively, I would encourage you to raise the issue with Service Fabric directly to add index support to IReliableDictionary directly :)

jessebenson avatar Mar 04 '20 17:03 jessebenson

Thanks a lot. This is very useful.

jfalameda avatar Mar 04 '20 18:03 jfalameda

Just to make sure, you are proposing that I create a separate dictionary? Or that I just wrap the IReliableDictionary into the IReliableIndexedDictionary and then perform delete/add?

Kind regards, José.

jfalameda avatar Mar 04 '20 21:03 jfalameda

I was suggesting using the same dictionary, something like below:

var dict = await stateManager.GetAsync<...>("dict-name");
var index = await stateManager.GetIndexedAsync<...>("dict-name");
for ((key, value) in dict) {
   using (var tx = ...) {
      await dict.RemoveAsync(key);
      await index.AddAsync(key, value);
      await tx.CommitAsync();
   }
}

jessebenson avatar Mar 04 '20 23:03 jessebenson