public void UpgradeGsm() { // Get shard map manager ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); // Sanity check setup: version should be 1.0 VerifyGlobalStore(smm, new Version(1, 0)); // Upgrade to version 1.0: no-op smm.UpgradeGlobalStore(new Version(1, 0)); VerifyGlobalStore(smm, new Version(1, 0)); // Upgrade to version 1.1 smm.UpgradeGlobalStore(new Version(1, 1)); VerifyGlobalStore(smm, new Version(1, 1)); // Upgrade to version 1.2 smm.UpgradeGlobalStore(new Version(1, 2)); VerifyGlobalStore(smm, new Version(1, 2)); // Upgrade to latest version smm.UpgradeGlobalStore(); VerifyGlobalStore(smm, GlobalConstants.GsmVersionClient); }
public void UpgradeGSM() { // Get shard map manager ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); try { ShardMap testsm = smm.CreateListShardMap <int>(ShardMapManagerUpgradeTests.s_shardMapNames[0]); Assert.IsNotNull(testsm); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCode.GlobalStoreVersionMismatch, sme.ErrorCode); } // Upgrade to version 1.0: no-op smm.UpgradeGlobalStore(new Version(1, 0)); // Upgrade to version 1.1 smm.UpgradeGlobalStore(new Version(1, 1)); // Below call should succeed as latest supported major version of library matches major version of deployed store. ShardMap sm = smm.CreateListShardMap <int>(ShardMapManagerUpgradeTests.s_shardMapNames[0]); Assert.IsNotNull(sm); // Upgrade to version 1.2 smm.UpgradeGlobalStore(new Version(1, 2)); // Upgrade to latest version (1.2): no-op smm.UpgradeGlobalStore(); }
public void UpgradeLsm() { // Get shard map manager ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); // upgrade GSM to latest version. smm.UpgradeGlobalStore(); VerifyGlobalStore(smm, GlobalConstants.GsmVersionClient); // deploy LSM initial version. ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, s_shardedDBs[0]); smm.UpgradeLocalStore(sl, s_initialLsmVersion); // upgrade to version 1.1 smm.UpgradeLocalStore(sl, new Version(1, 1)); // Library is still at LSM major version 1, so adding shard with LSM 1.0 should succeed. // Library will see that LSM schema already exists at 'sl' and hence will not deploy LSM again, will just try to add the shard. // CreateShard will not work with LSM initial version (1.0) as it only has 'StoreVersion' column in ShardMApManagerLocal table, from 1.1 onwards it follows latest schema for version table. ListShardMap <int> listsm = smm.CreateListShardMap <int>(ShardMapManagerUpgradeTests.s_shardMapNames[0]); listsm.CreateShard(sl); // upgrade to version 1.2 smm.UpgradeLocalStore(sl, new Version(1, 2)); // upgrade to latest version (1.2): no-op smm.UpgradeLocalStore(sl); }
public void GetDistinctLocations() { // Get shard map manager and 2 shard maps. ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); // Upgrade GSM to latest version smm.UpgradeGlobalStore(); // create shard maps foreach (string name in ShardMapManagerUpgradeTests.s_shardMapNames) { ShardMap sm = smm.CreateListShardMap <int>(name); Assert.IsNotNull(sm); } ShardMap sm1 = smm.GetShardMap(ShardMapManagerUpgradeTests.s_shardMapNames[0]); Assert.IsNotNull(sm1); ShardMap sm2 = smm.GetShardMap(ShardMapManagerUpgradeTests.s_shardMapNames[1]); Assert.IsNotNull(sm2); // Add shards to the shard maps. ShardLocation sl1 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapManagerUpgradeTests.s_shardedDBs[0]); ShardLocation sl2 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapManagerUpgradeTests.s_shardedDBs[1]); ShardLocation sl3 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapManagerUpgradeTests.s_shardedDBs[2]); Shard s1 = sm1.CreateShard(sl1); Shard s2 = sm1.CreateShard(sl2); Shard s3 = sm1.CreateShard(sl3); Shard s4 = sm2.CreateShard(sl2); Shard s5 = sm2.CreateShard(sl3); int count = 0; foreach (ShardLocation sl in smm.GetDistinctShardLocations()) { count++; } Assert.AreEqual(3, count); }
public void TestLockingFixInVersion1_2() { // Get shard map manager ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); // Upgrade to version 1.1 smm.UpgradeGlobalStore(new Version(1, 1)); // Create a range shard map and add few mappings RangeShardMap <int> rsm = smm.CreateRangeShardMap <int>(ShardMapManagerUpgradeTests.s_shardMapNames[1]); Assert.IsNotNull(rsm); Shard s = rsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapManagerUpgradeTests.s_shardedDBs[0])); Assert.IsNotNull(s); RangeMapping <int> m1 = rsm.CreateRangeMapping(new Range <int>(1, 10), s); RangeMapping <int> m2 = rsm.CreateRangeMapping(new Range <int>(10, 20), s); RangeMapping <int> m3 = rsm.CreateRangeMapping(new Range <int>(20, 30), s); // Lock first 2 mappings with same lockownerid and third with a different lock owner id MappingLockToken t1 = MappingLockToken.Create(); MappingLockToken t2 = MappingLockToken.Create(); rsm.LockMapping(m1, t1); rsm.LockMapping(m2, t1); rsm.LockMapping(m3, t2); // now try to unlock using token t2. In store version 1.1 it will unlock all mappings rsm.UnlockMapping(t2); foreach (RangeMapping <int> m in rsm.GetMappings()) { Assert.AreEqual(MappingLockToken.NoLock, rsm.GetMappingLockOwner(m)); } // Now upgrade to version 1.2 and try same scenario above. smm.UpgradeGlobalStore(new Version(1, 2)); rsm.LockMapping(m1, t1); rsm.LockMapping(m2, t1); rsm.LockMapping(m3, t2); // Unlock using token t1. It should just unlock 2 mappings and leave last one locked. rsm.UnlockMapping(t1); Assert.AreEqual(MappingLockToken.NoLock, rsm.GetMappingLockOwner(rsm.GetMappingForKey(5))); Assert.AreEqual(MappingLockToken.NoLock, rsm.GetMappingLockOwner(rsm.GetMappingForKey(15))); Assert.AreEqual(t2, rsm.GetMappingLockOwner(rsm.GetMappingForKey(25))); // Cleanup - Delete all mappings. shard will be removed in test cleanup. rsm.UnlockMapping(t2); RangeMappingUpdate ru = new RangeMappingUpdate(); ru.Status = MappingStatus.Offline; foreach (RangeMapping <int> m in rsm.GetMappings()) { rsm.DeleteMapping(rsm.UpdateMapping(m, ru)); } }