Ejemplo n.º 1
0
        public static void Initialize(Silo silo, IGrainFactory grainFactory, string reminderTableAssembly = null)
        {
            var config = silo.GlobalConfig;
            var serviceType = config.ReminderServiceType;
            var logger = TraceLogger.GetLogger("ReminderTable");

            switch (serviceType)
            {
                default:
                    throw new NotSupportedException(
                        String.Format(
                            "The reminder table does not currently support service provider {0}.",
                            serviceType));

                case GlobalConfiguration.ReminderServiceProviderType.SqlServer:
                    Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(Constants.ORLEANS_SQL_UTILS_DLL, logger);
                    return;

                case GlobalConfiguration.ReminderServiceProviderType.AzureTable:
                    Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(Constants.ORLEANS_AZURE_UTILS_DLL, logger);
                    return;

                case GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain:
                    Singleton = grainFactory.GetGrain<IReminderTableGrain>(Constants.ReminderTableGrainId);
                    return;

                case GlobalConfiguration.ReminderServiceProviderType.MockTable:
                    Singleton = new MockReminderTable(config.MockReminderTableTimeout);
                    return;

                case GlobalConfiguration.ReminderServiceProviderType.Custom:
                    Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(reminderTableAssembly, logger);
                    return;
            }
        }
Ejemplo n.º 2
0
 public void TestCleanup()
 {
     if (remindersTable != null && SiloInstanceTableTestConstants.DeleteEntriesAfterTest)
     {
         remindersTable.TestOnlyClearTable().Wait();
         remindersTable = null;
     }
     logger.Info("Test {0} completed - Outcome = {1}", TestContext.TestName, TestContext.CurrentTestOutcome);
 }
Ejemplo n.º 3
0
        internal static async Task ReminderTableUpsertParallel(IReminderTable reminder)
        {
            var grainRef = MakeTestGrainReference();
            var period = TimeSpan.FromMinutes(1);
            var reminderName = "testReminderName";
            var startAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(1));
            var results = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => UpsertReminder(reminder, grainRef, reminderName, startAt, period)));

            Assert.IsTrue(results.Distinct().Count() == results.Length);
        }
 internal static async Task ReminderTableUpsertTwice(IReminderTable reminder)
 {
     var grainRef = MakeTestGrainReference();
     var period = TimeSpan.FromMinutes(1);
     var reminderName = "testReminderName";
     var startAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(1));
     var etag1 = await UpsertReminder(reminder, grainRef, reminderName, startAt, period);
     var etag2 = await UpsertReminder(reminder, grainRef, reminderName, startAt, period);
     Assert.AreNotEqual(etag1, etag2);
 }
Ejemplo n.º 5
0
 private static async Task<string> UpsertReminder(IReminderTable reminder, GrainReference grainRef, string reminderName, DateTime startAt, TimeSpan period)
 {
     var reminderRow = new ReminderEntry
                       {
                           GrainRef = grainRef,
                           Period = period,
                           StartAt = startAt,
                           ReminderName = reminderName
                       };
     return await reminder.UpsertRow(reminderRow);
 }
Ejemplo n.º 6
0
        private static async Task TestRemindersHashInterval(IReminderTable reminderTable, uint beginHash, uint endHash,
            uint[] remindersHashes)
        {
            var rowsTask = reminderTable.ReadRows(beginHash, endHash);
            var expectedHashes = beginHash < endHash
                ? remindersHashes.Where(r => r > beginHash && r <= endHash)
                : remindersHashes.Where(r => r > beginHash || r <= endHash);

            HashSet<uint> expectedSet = new HashSet<uint>(expectedHashes);
            var returnedHashes = (await rowsTask).Reminders.Select(r => r.GrainRef.GetUniformHashCode());
            var returnedSet = new HashSet<uint>(returnedHashes);

            Assert.IsTrue(returnedSet.SetEquals(expectedSet));
        }
Ejemplo n.º 7
0
        internal static async Task ReminderTableTest(IReminderTable reminderTable)
        {
            Guid guid = Guid.NewGuid();
            var results = await Task.WhenAll(Enumerable.Range(0, 10).
                Select(x => reminderTable.UpsertRow(CreateReminder(MakeTestGrainReference(guid), "0"))));

            Assert.AreEqual(results.Distinct().Count(), results.Length);

            await Task.WhenAll(Enumerable.Range(1, 999).Select(async i =>
            {
                GrainReference grainRef = MakeTestGrainReference(Guid.NewGuid());
                await reminderTable.UpsertRow(CreateReminder(grainRef, i.ToString()));
            }));

            var rows = await reminderTable.ReadRows(0, uint.MaxValue);

            Assert.AreEqual(rows.Reminders.Count, 1000);

            rows = await reminderTable.ReadRows(0, 0);

            Assert.AreEqual(rows.Reminders.Count, 1000);

            var remindersHashes = rows.Reminders.Select(r => r.GrainRef.GetUniformHashCode()).ToArray();
            
            SafeRandom random = new SafeRandom();

            await Task.WhenAll(Enumerable.Repeat(
                        TestRemindersHashInterval(reminderTable, (uint) random.Next(), (uint) random.Next(),
                            remindersHashes), 1000));

            var reminder = rows.Reminders.First();

            var shouldExist = await reminderTable.ReadRow(reminder.GrainRef, reminder.ReminderName);

            Assert.IsNotNull(shouldExist);

            string etagTemp = reminder.ETag;

            reminder.ETag = await reminderTable.UpsertRow(reminder);

            var removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, etagTemp);
            Assert.IsFalse(removeRowRes, "should have failed. Etag is wrong");
            removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, "bla", reminder.ETag);
            Assert.IsFalse(removeRowRes, "should have failed. reminder name is wrong");
            removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, reminder.ETag);
            Assert.IsTrue(removeRowRes, "should have succeeded. Etag is right");
            removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, reminder.ETag);
            Assert.IsFalse(removeRowRes, "should have failed. reminder shouldn't exist");
        }
Ejemplo n.º 8
0
        public void TestInitialize()
        {
            logger = TraceLogger.GetLogger(GetType().Name, TraceLogger.LoggerType.Application);
            var serviceId = Guid.NewGuid();
            var deploymentId = "test-" + serviceId;

            logger.Info("DeploymentId={0}", deploymentId);

            var globalConfiguration = new GlobalConfiguration
            {
                ServiceId = serviceId,
                DeploymentId = deploymentId,
                AdoInvariantForReminders = GetAdoInvariant(),
                DataConnectionStringForReminders = GetConnectionString()
            };

            var rmndr = CreateRemindersTable();
            rmndr.Init(globalConfiguration, logger).WithTimeout(TimeSpan.FromMinutes(1)).Wait();
            remindersTable = rmndr;
        }
        private async Task TestTableInsertRate(IReminderTable reminderTable, double numOfInserts)
        {
            DateTime startedAt = DateTime.UtcNow;

            try
            {
                List<Task<bool>> promises = new List<Task<bool>>();
                for (int i = 0; i < numOfInserts; i++)
                {
                    //"177BF46E-D06D-44C0-943B-C12F26DF5373"
                    string s = string.Format("177BF46E-D06D-44C0-943B-C12F26D{0:d5}", i);

                    var e = new ReminderEntry
                    {
                        //GrainId = GrainId.GetGrainId(new Guid(s)),
                        GrainRef = GrainReference.FromGrainId(GrainId.NewId()),
                        ReminderName = "MY_REMINDER_" + i,
                        Period = TimeSpan.FromSeconds(5),
                        StartAt = DateTime.UtcNow
                    };

                    int capture = i;
                    Task<bool> promise = Task.Run(async () =>
                    {
                        await reminderTable.UpsertRow(e);
                        output.WriteLine("Done " + capture);
                        return true;
                    });
                    promises.Add(promise);
                    log.Info("Started " + capture);
                }
                log.Info("Started all, now waiting...");
                await Task.WhenAll(promises).WithTimeout(TimeSpan.FromSeconds(500));
            }
            catch (Exception exc)
            {
                log.Info("Exception caught {0}", exc);
            }
            TimeSpan dur = DateTime.UtcNow - startedAt;
            log.Info("Inserted {0} rows in {1}, i.e., {2:f2} upserts/sec", numOfInserts, dur, (numOfInserts / dur.TotalSeconds));
        }
Ejemplo n.º 10
0
 public LocalReminderServiceFactory(IReminderTable reminderTable, ILoggerFactory loggerFactory)
 {
     this.reminderTable = reminderTable;
     logger             = loggerFactory.CreateLogger <LocalReminderServiceFactory>();
     this.loggerFactory = loggerFactory;
 }
Ejemplo n.º 11
0
 public ReminderTestGrain2(IServiceProvider services, IReminderTable reminderTable)
 {
     this.reminderTable = reminderTable;
     this.unvalidatedReminderRegistry = new UnvalidatedReminderRegistry(services);
 }
Ejemplo n.º 12
0
 public ReminderTestGrain2(IServiceProvider services, IReminderTable reminderTable, ILoggerFactory loggerFactory)
 {
     this.reminderTable = reminderTable;
     this.unvalidatedReminderRegistry = new UnvalidatedReminderRegistry(services);
     this.logger = loggerFactory.CreateLogger($"{this.GetType().Name}-{this.IdentityString}");
 }
Ejemplo n.º 13
0
        private List <SiloHandle> getSilosToFail(Fail fail, int numOfFailures)
        {
            List <SiloHandle> failures = new List <SiloHandle>();
            int count = 0, index = 0;

            // Figure out the primary directory partition and the silo hosting the ReminderTableGrain.
            bool                     usingReminderGrain = Primary.Silo.GlobalConfig.ReminderServiceType.Equals(GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain);
            IReminderTable           tableGrain         = GrainClient.GrainFactory.GetGrain <IReminderTableGrain>(Constants.ReminderTableGrainId);
            SiloAddress              reminderTableGrainPrimaryDirectoryAddress = Primary.Silo.LocalGrainDirectory.GetPrimaryForGrain(((GrainReference)tableGrain).GrainId);
            SiloHandle               reminderTableGrainPrimaryDirectory        = GetActiveSilos().Where(sh => sh.Silo.SiloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress)).FirstOrDefault();
            List <ActivationAddress> addresses = null;
            bool                     res       = reminderTableGrainPrimaryDirectory.Silo.LocalGrainDirectory.LocalLookup(((GrainReference)tableGrain).GrainId, out addresses);
            ActivationAddress        reminderGrainActivation = addresses.FirstOrDefault();

            SortedList <int, SiloHandle> ids = new SortedList <int, SiloHandle>();

            foreach (var siloHandle in GetActiveSilos())
            {
                SiloAddress siloAddress = siloHandle.Silo.SiloAddress;
                if (siloAddress.Equals(Primary.Silo.SiloAddress))
                {
                    continue;
                }
                // Don't fail primary directory partition and the silo hosting the ReminderTableGrain.
                if (usingReminderGrain)
                {
                    if (siloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress) || siloAddress.Equals(reminderGrainActivation.Silo))
                    {
                        continue;
                    }
                }
                ids.Add(siloHandle.Silo.SiloAddress.GetConsistentHashCode(), siloHandle);
            }

            // we should not fail the primary!
            // we can't guarantee semantics of 'Fail' if it evalutes to the primary's address
            switch (fail)
            {
            case Fail.First:
                index = 0;
                while (count++ < numOfFailures)
                {
                    while (failures.Contains(ids.Values[index]))
                    {
                        index++;
                    }
                    failures.Add(ids.Values[index]);
                }
                break;

            case Fail.Last:
                index = ids.Count - 1;
                while (count++ < numOfFailures)
                {
                    while (failures.Contains(ids.Values[index]))
                    {
                        index--;
                    }
                    failures.Add(ids.Values[index]);
                }
                break;

            case Fail.Random:
            default:
                while (count++ < numOfFailures)
                {
                    SiloHandle r = ids.Values[random.Next(ids.Count)];
                    while (failures.Contains(r))
                    {
                        r = ids.Values[random.Next(ids.Count)];
                    }
                    failures.Add(r);
                }
                break;
            }
            return(failures);
        }
Ejemplo n.º 14
0
        internal LocalReminderService(SiloAddress addr, GrainId id, IConsistentRingProvider ring, OrleansTaskScheduler localScheduler, IReminderTable reminderTable)
            : base(id, addr)
        {
            logger = TraceLogger.GetLogger("ReminderService", TraceLogger.LoggerType.Runtime);

            localReminders     = new Dictionary <ReminderIdentity, LocalReminderData>();
            this.ring          = ring;
            scheduler          = localScheduler;
            this.reminderTable = reminderTable;
            status             = ReminderServiceStatus.Booting;
            myRange            = null;
            localTableSequence = 0;
            tardinessStat      = AverageTimeSpanStatistic.FindOrCreate(StatisticNames.REMINDERS_AVERAGE_TARDINESS_SECONDS);
            IntValueStatistic.FindOrCreate(StatisticNames.REMINDERS_NUMBER_ACTIVE_REMINDERS, () => localReminders.Count);
            ticksDeliveredStat = CounterStatistic.FindOrCreate(StatisticNames.REMINDERS_COUNTERS_TICKS_DELIVERED);
            startedTask        = new TaskCompletionSource <bool>();
        }
Ejemplo n.º 15
0
 public LocalReminderServiceFactory(IReminderTable reminderTable)
 {
     this.reminderTable = reminderTable;
     logger             = LogManager.GetLogger("ReminderFactory", LoggerType.Runtime);
 }
Ejemplo n.º 16
0
 public DashboardRemindersGrain(IReminderTable reminderTable)
 {
     _reminderTable = reminderTable;
 }
Ejemplo n.º 17
0
        private async Task <List <SiloHandle> > getSilosToFail(Fail fail, int numOfFailures)
        {
            List <SiloHandle> failures = new List <SiloHandle>();
            int count = 0, index = 0;

            // Figure out the primary directory partition and the silo hosting the ReminderTableGrain.
            bool           usingReminderGrain = this.HostedCluster.ClusterConfiguration.Globals.ReminderServiceType.Equals(GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain);
            IReminderTable tableGrain         = GrainClient.GrainFactory.GetGrain <IReminderTableGrain>(Constants.ReminderTableGrainId);
            var            tableGrainId       = ((GrainReference)tableGrain).GrainId;
            SiloAddress    reminderTableGrainPrimaryDirectoryAddress = (await TestUtils.GetDetailedGrainReport(tableGrainId, this.HostedCluster.Primary)).PrimaryForGrain;
            // ask a detailed report from the directory partition owner, and get the actionvation addresses
            var addresses = (await TestUtils.GetDetailedGrainReport(tableGrainId, this.HostedCluster.GetSiloForAddress(reminderTableGrainPrimaryDirectoryAddress))).LocalDirectoryActivationAddresses;
            ActivationAddress reminderGrainActivation = addresses.FirstOrDefault();

            SortedList <int, SiloHandle> ids = new SortedList <int, SiloHandle>();

            foreach (var siloHandle in this.HostedCluster.GetActiveSilos())
            {
                SiloAddress siloAddress = siloHandle.SiloAddress;
                if (siloAddress.Equals(this.HostedCluster.Primary.SiloAddress))
                {
                    continue;
                }
                // Don't fail primary directory partition and the silo hosting the ReminderTableGrain.
                if (usingReminderGrain)
                {
                    if (siloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress) || siloAddress.Equals(reminderGrainActivation.Silo))
                    {
                        continue;
                    }
                }
                ids.Add(siloHandle.SiloAddress.GetConsistentHashCode(), siloHandle);
            }

            // we should not fail the primary!
            // we can't guarantee semantics of 'Fail' if it evalutes to the primary's address
            switch (fail)
            {
            case Fail.First:
                index = 0;
                while (count++ < numOfFailures)
                {
                    while (failures.Contains(ids.Values[index]))
                    {
                        index++;
                    }
                    failures.Add(ids.Values[index]);
                }
                break;

            case Fail.Last:
                index = ids.Count - 1;
                while (count++ < numOfFailures)
                {
                    while (failures.Contains(ids.Values[index]))
                    {
                        index--;
                    }
                    failures.Add(ids.Values[index]);
                }
                break;

            case Fail.Random:
            default:
                while (count++ < numOfFailures)
                {
                    SiloHandle r = ids.Values[random.Next(ids.Count)];
                    while (failures.Contains(r))
                    {
                        r = ids.Values[random.Next(ids.Count)];
                    }
                    failures.Add(r);
                }
                break;
            }
            return(failures);
        }
        private async Task <IEnumerable <ReminderEntry> > GetAllRows(IReminderTable table)
        {
            ReminderTableData data = await table.ReadRows(0, 0xffffffff);

            return(data.Reminders);
        }
 private async Task<IEnumerable<ReminderEntry>> GetAllRows(IReminderTable table)
 {
     ReminderTableData data = await table.ReadRows(0, 0xffffffff);
     return data.Reminders;
 }
Ejemplo n.º 20
0
 public DashboardRemindersGrain(IServiceProvider serviceProvider)
 {
     reminderTable = serviceProvider.GetService(typeof(IReminderTable)) as IReminderTable;
 }