darioquintana
darioquintana / nhibernate-shards Goto Github PK
View Code? Open in Web Editor NEWShards for NHibernate
Home Page: www.nhforge.org
Shards for NHibernate
Home Page: www.nhforge.org
darioquintana
I'm converting my sessions to use sharded sessions based on a tenant model (explictly open a session factory and then the session from that). My future queries are throwing an error:
NHibernate.Shards.Session.ShardedSessionImpl+DelegatingSessionImpl requires to implement NHibernate.Impl.AbstractSessionImpl class to support future batch
Are there any plans to implement Future batch queries? I appreciate that it's not really appropriate for cross-shard queries but the shard-per-tenant model is common and there is nothing to stop future queries in that scenario.
My alternative is to get a real session instead...
I can see that the IShardedSession api has a "GetSessionForObject" that returns an ISession (but at this stage I don't have an associated object to use) and the ShardedSessionImpl class has a private AnySession (but not exposed) and an EstablishFor(IShard shard) method but the only way I can see to get a shard is to use the ShardedSessionImpl Shards property - knowing that I only have the one shard.
Can any of these methods be exposed via the interface? (e.g the EstablishFor and Shard method/property?)
Is there a better way to do this?
Hi,
I’m trying work out if there is a sharding strategy based on business key (customer id). I can see the round robin example but that doesn’t seem appropriate.
We are working with tenanted data.... so all entities in a session will belong to the same shard.... so conceptually when we create a session we want to say ‘create a session for customer X’ and the sharding framework will either know that X relates to shard Y or that X isn’t in a shard so it will assign one.
Is this available out of the box and I’ve missed it in the code?
Thanks
My works in a problem. https://github.com/mesutcakir/NHibernate-Shards?organization=mesutcakir&organization=mesutcakir
`İşlenmeyen Özel Durum: NHibernate.Shards.CrossShardAssociationException: Object of entity type 'NHibernate.Shards.Demo.Task' is on shard '0' but an associated object of type 'NHibernate.Shards.Demo.Project' is on shard '1'.
konum: NHibernate.Shards.Session.ShardedSessionImpl.ThrowIfConflictingShardId(String entityName, ShardId shardId, KeyValuePair2 associatedShardId)
konum: NHibernate.Shards.Session.ShardedSessionImpl.TryGetShardIdOfAssociatedObject(String entityName, Object entity, ShardId& result)
konum: NHibernate.Shards.Session.ShardedSessionImpl.SelectShardIdForNewEntity(String entityName, Object entity)
konum: NHibernate.Shards.Session.ShardedSessionImpl.Save(String entityName, Object obj)
konum: NHibernate.Shards.Session.ShardedSessionImpl.Save(Object obj)
konum: NHibernate.Shards.Demo.FirmBasedApp.CreateTask(ISession session, Project project, String name, DayBase dayBase)
konum: NHibernate.Shards.Demo.FirmBasedApp.AddData()
konum: NHibernate.Shards.Demo.FirmBasedApp.Run()
konum: NHibernate.Shards.Demo.FirmBasedApp.Main(String[] args)
Press any key to continue . . .`
I search this referances. Virtual Shards - https://docs.jboss.org/hibernate/stable/shards/reference/en/html/shards-resharding.html
But not working. "System.Collections.Generic.KeyNotFoundException"
`var virtualShardMap = new Dictionary<short, short>
{
{ 0, 0 },
{ 1, 0 },
{ 2, 0 },
{ 3, 0 }
};
return new ShardedConfiguration(prototypeConfig, shardConfigs, shardStrategyFactory, virtualShardMap);`
İşlenmeyen Özel Durum: System.Collections.Generic.KeyNotFoundException: Verilen anahtar sözlükte yoktu.
konum: System.ThrowHelper.ThrowKeyNotFoundException()
konum: System.Collections.Generic.Dictionary`2.get_Item(TKey key)
konum: NHibernate.Shards.ShardedConfiguration..ctor(Configuration prototypeConfiguration, IEnumerable`1 shardConfigs, IShardStrategyFactory shardStrategyFactory, Dictionary`2 virtualShardToShardMap)
konum: NHibernate.Shards.Demo.FirmBasedApp.BuildShardedConfiguration()
konum: NHibernate.Shards.Demo.FirmBasedApp.Run()
konum: NHibernate.Shards.Demo.FirmBasedApp.Main(String[] args)
Press any key to continue . . .
NHibernate.Shards => ShardedConfiguration
if (virtualShardToShardMap.Count != 0)
{
// build the map from shard to set of virtual shards
shardToVirtualShardIdMap = new Dictionary<short, ICollection<ShardId>>();
foreach (var pair in virtualShardToShardMap)
{
var set = shardToVirtualShardIdMap[(pair.Value)]; //**Problem Here.**
// see if we already have a set of virtual shards
if (set == null)
{
// we don't, so create it and add it to the map
set = new HashSet<ShardId>();
shardToVirtualShardIdMap.Add(pair.Value, set);
}
set.Add(new ShardId(pair.Key));
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.