void Populate(ISortedDictionary <object, object> PeopleStore)
        {
            int ZipCodeCtr = 5000;

            CacheRecord[] BatchedRecords = new CacheRecord[BatchCount];
            int           BatchedIndex   = 0;

            for (int i = 0; i < MaxCount; i++)
            {
                int    pid = (int)PeopleStore.GetNextSequence();
                Person p   = new Person()
                {
                    FirstName = string.Format("Joe{0}", pid),
                    LastName  = string.Format("Peter{0}", pid)
                };
                BatchedRecords[BatchedIndex] = new CacheRecord()
                {
                    p    = p,
                    blob = new PersonBlob
                    {
                        Blob = new byte[PersonBlob.BlobAvgSize]
                    }
                };
                BatchedRecords[BatchedIndex].blob.Blob[0] = 1;
                BatchedRecords[BatchedIndex].blob.Blob[5] = 54;
                BatchedIndex++;
                if (BatchedIndex == BatchCount)
                {
                    for (int i2 = 0; i2 < BatchedIndex; i2++)
                    {
                        PeopleStore.Add(BatchedRecords[i2].p, BatchedRecords[i2].blob);
                    }
                    PeopleStore.Flush();
                    if (i % 500 == 0)
                    {
                        ZipCodeCtr++;
                    }
                    BatchedIndex = 0;
                }
            }
            if (BatchedIndex > 0)
            {
                for (int i2 = 0; i2 < BatchedIndex; i2++)
                {
                    PeopleStore.Add(BatchedRecords[i2].p, BatchedRecords[i2].blob);
                }
                PeopleStore.Flush();
            }
        }
예제 #2
0
        void Populate(ISortedDictionary <string, object> Store)
        {
            for (int i = 0; i < MaxCount; i++)
            {
                int    pid   = (int)Store.GetNextSequence();
                string key   = string.Empty;
                object value = null;
                switch (i % 4)
                {
                case 0:
                    key   = string.Format("PersonBlob{0}", pid);
                    value = new PersonBlob
                    {
                        Blob = new byte[PersonBlob.BlobAvgSize]
                    };
                    break;

                case 1:
                    key   = string.Format("Person{0}", pid);
                    value = new Person
                    {
                        FirstName = string.Format("Joe {0}", pid),
                        LastName  = string.Format("Curly {0}", pid)
                    };
                    break;

                case 2:
                    key   = string.Format("Address{0}", pid);
                    value = new Address
                    {
                        Street  = string.Format("123 Love Lane {0}", pid),
                        City    = "Fremont",
                        State   = "California",
                        Country = "U.S.A.",
                        ZipCode = 94599
                    };
                    break;

                case 3:
                    key   = string.Format("Dept{0}", pid);
                    value = new Department
                    {
                        Id   = pid,
                        Name = string.Format("Dept {0}", pid)
                    };
                    break;
                }
                Store.Add(key, value);
                if (i % 2000 == 0)
                {
                    Store.Flush();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Sample code to show how to create nested Sorted Dictionaries.
        /// I.e. - Collections within Collection scenario.
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: NestedSortedDictionary demo started...", DateTime.Now);

            const int    CollCount = 50;
            ITransaction Trans;

            IStoreFactory Factory = new StoreFactory();

            //** Create/Get the Main Collection which we will store the nested "People" Sorted Dictionaries in below code...
            ISortedDictionary <string, GeneralPurpose <long, Person> > Collections =
                Factory.Get <string, GeneralPurpose <long, Person> >(Server.SystemFile.Store, "MainCollection");

            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = Factory.Get <long, Person>(Collections, CollectionName);
                Trans = store.Transaction;
                if (store.Count == 0)
                {
                    Populate(store);
                    store.Flush();
                    //store.Dispose();
                }
                //else
                //    store.Dispose();
                if (i >= 10)
                {
                    //** get the table 5 tables "ago"
                    store = Factory.Get <long, Person>(Collections, string.Format("People{0}", i - 5));
                    //** delete the table retrieved...
                    //store.Clear();

                    store.Rename("foo");

                    ISortedDictionary <long, Person> fooStore = Factory.Get <long, Person>(Collections, "foo");
                    //store.Delete();
                }
                Trans.Commit();
                server.BeginTransaction();
            }
            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = Factory.Get <long, Person>(Collections, CollectionName, createIfNotExist: false);
                if (store != null)
                {
                    ReadAll(store);
                    //store.Dispose();
                }
            }
            Console.WriteLine("{0}: NestedSortedDictionary demo ended...", DateTime.Now);
        }
예제 #4
0
        void Populate(ObjectServer server,
                      ISortedDictionary <long, Person> PeopleStore,
                      int maxCount,
                      int seed
                      )
        {
            int ZipCodeCtr = 5000;

            for (int i = seed; i < maxCount; i++)
            {
                if (i == maxCount - 2)
                {
                    object o = 90;
                }
                int     aid  = i;
                Address addr = new Address()
                {
                    AddressID = aid,
                    Key       = new AddressKey()
                    {
                        Street  = string.Format("143{0} LoveLane", aid),
                        City    = "Fremont",
                        Country = "USA",
                        State   = "California",
                        ZipCode = ZipCodeCtr.ToString()
                    }
                };
                int    pid = (int)PeopleStore.GetNextSequence();
                Person p   = new Person()
                {
                    PersonID  = pid,
                    AddressID = addr.AddressID,
                    Key       = new PersonKey()
                    {
                        FirstName = string.Format("Joe{0}", pid),
                        LastName  = string.Format("Peter{0}", pid)
                    },
                    PhoneNumber = "510-555-9999"
                };
                PeopleStore.Add(p.PersonID, p);
                if (i % 5000 == 0)
                {
                    ZipCodeCtr++;
                    PeopleStore.Flush();
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Sample code that creates 50 tables and deletes 40 of them.
        /// Reads all the records of the leftover 10 tables. Intention of
        /// this example is to test table space recycling and to show to the
        /// user feature to delete a table in SOP.
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: CollectionRecycling demo started...", DateTime.Now);

            const int     CollCount = 50;
            ITransaction  Trans;
            IStoreFactory sf = new StoreFactory();

            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = sf.Get <long, Person>(Server.SystemFile.Store, CollectionName);
                Trans = store.Transaction;
                if (store.Count == 0)
                {
                    Populate(store);
                    store.Flush();
                    //store.Dispose();
                }
                //else
                //    store.Dispose();
                if (i >= 10)
                {
                    //** get the table 5 tables "ago"
                    store = sf.Get <long, Person>(Server.SystemFile.Store, string.Format("People{0}", i - 5));
                    //** delete the table retrieved...
                    store.Delete();
                }
                Trans.Commit();
                server.BeginTransaction();
            }
            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = sf.Get <long, Person>(Server.SystemFile.Store, CollectionName);
                if (store != null)
                {
                    ReadAll(store);
                    //store.Dispose();
                }
            }
            Console.WriteLine("{0}: CollectionRecycling demo ended...", DateTime.Now);
        }
예제 #6
0
        void Stress(ISortedDictionary <int, Person> PeopleStore,
                    ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            PeopleStore.HintBatchCount  = 100;
            AddressStore.HintBatchCount = 100;
            PeopleStore.MoveLast();
            int    mx  = MaxCount;
            Random rdm = new Random(mx);

            //** NOTE: no batching implemented here, just basic operations...
            //** see Populate function how to do batch Add in set of 1000 which optimizes SOP/Disk buffer usage
            //** batch remove can also be done to optimize usage of such buffers & minimize file pointer jumps.
            for (int i = 0; i < MaxCount / 10; i++)
            {
                int    no = rdm.Next(mx);
                Person p;

                if (i % 2 == 0)
                {
                    Address addr = new Address();
                    addr.AddressID = (int)AddressStore.GetNextSequence();
                    addr.City      = "Fremont";
                    addr.Country   = "USA";
                    addr.State     = "California";
                    addr.Street    = string.Format("143{0} LoveLane", i);
                    addr.ZipCode   = "99999";
                    AddressStore.Add(addr.AddressID, addr);

                    p           = new Person();
                    p.AddressID = addr.AddressID;
                    int i2 = no;
                    p.FirstName   = string.Format("Joe{0}", i2);
                    p.LastName    = "Peter";
                    p.PhoneNumber = "510-555-9999";
                    PeopleStore.Add(i2, p);
                }
                else
                {
                    if (PeopleStore.TryGetValue(no, out p))
                    {
                        AddressStore.Remove(p.AddressID);
                        PeopleStore.Remove(no);
                    }
                }
                if (i % 500 <= 1)
                {
                    if (i % 2 == 0)
                    {
                        PeopleStore.Transaction.Commit();
                    }
                    else
                    {
                        PeopleStore.Flush();
                        AddressStore.Flush();
                        PeopleStore.Transaction.Rollback();
                    }
                    server.BeginTransaction();
                }
            }
            Console.WriteLine("Stress ended.");
        }