Esempio n. 1
0
        void ReadAll(ref ISortedDictionary <string, object> Store)
        {
            int       Ctr        = 0;
            string    key        = null;
            const int batchCount = 1000;

            string[] batch = new string[batchCount];
            for (int i = 0; i < MaxCount; i++)
            {
                Ctr++;
                switch (i % 4)
                {
                case 0:
                    key = string.Format("PersonBlob{0}", Ctr);
                    break;

                case 1:
                    key = string.Format("Person{0}", Ctr);
                    break;

                case 2:
                    key = string.Format("Address{0}", Ctr);
                    break;

                case 3:
                    key = string.Format("Dept{0}", Ctr);
                    break;
                }
                batch[i % batchCount] = key;
                if (i > 0 && i % batchCount == 0)
                {
                    QueryResult <string>[] result;
                    if (!Store.Query(batch.Select((a) => new QueryExpression <string>()
                    {
                        Key = a
                    }).ToArray(), out result))
                    {
                        Console.WriteLine("Failed! 'can't find object {0}.", key);
                    }
                    else
                    {
                        foreach (var o in result)
                        {
                            if (!o.Found)
                            {
                                Console.WriteLine("Failed! 'can't find object {0}.", o.Key);
                            }
                            if (o.Value == null)
                            {
                                Console.WriteLine("Failed! 'found object {0} has null Value.", o.Key);
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Processed {0} records.", Ctr);
        }
Esempio n. 2
0
        // "Bulk" read all Person and Address records from respective Stores...
        private void Read(ISortedDictionary <PersonKey, Person> PeopleStore,
                          ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            PeopleStore.MoveFirst();
            // tell People Store it can do read ahead of 77 Persons.
            PeopleStore.HintBatchCount = 77;
            AddressStore.MoveFirst();
            // tell Address Store it can do read ahead of 78 Addresses.
            AddressStore.HintBatchCount = 78;
            KeyValuePair <int, int>[] AddressIDs = new KeyValuePair <int, int> [AddressBatchCount];
            int AddressBatchIndex = 0;

            for (int i = 1; i <= MaxCount; i++)
            {
                Person p = PeopleStore.CurrentValue;
                if (p.FirstName != string.Format("Joe{0}", i))
                {
                    Console.WriteLine("Error detected, expected Joe{0} not found in this sequence from disk", i);
                }
                else
                {
                    AddressIDs[AddressBatchIndex++] = new KeyValuePair <int, int>(p.AddressID, i);
                    if (AddressBatchIndex == AddressBatchCount)
                    {
                        int[] a2 = new int[AddressBatchCount];
                        for (int i2 = 0; i2 < AddressBatchCount; i2++)
                        {
                            a2[i2] = AddressIDs[i2].Key;
                        }
                        // Query a batch of 1000 addresses. NOTE: doing batch query is optimal operation
                        // as it minimizes segment jumps of the HDD "disk head".
                        QueryResult <int>[] Addresses;
                        if (AddressStore.Query(QueryExpression <int> .Package(a2), out Addresses))
                        {
                            for (int i2 = 0; i2 < AddressBatchCount; i2++)
                            {
                                Address addr = (Address)Addresses[i2].Value;
                                if (addr == null ||
                                    addr.Street != string.Format("143{0} LoveLane", AddressIDs[i2].Value))
                                {
                                    Console.WriteLine("Error detected, expected Address 143{0} not found in this sequence from disk",
                                                      AddressIDs[i2].Value);
                                }
                            }
                        }
                        AddressBatchIndex = 0;
                    }
                }
                PeopleStore.MoveNext();
            }
            if (!PeopleStore.EndOfTree())
            {
                Console.WriteLine("Expected EOT but isn't.");
            }
            Console.WriteLine("Reading all data({0}) ended.", MaxCount);
        }
Esempio n. 3
0
        void ReadAll(ISortedDictionary <int, Person> PeopleStore,
                     ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            Console.WriteLine("{0}: Start reading {1} records.", DateTime.Now, PeopleStore.Count);
            PeopleStore.MoveFirst();
            PeopleStore.HintBatchCount = 200;
            int[] Aids      = new int[1000];
            int   AidsIndex = 0;
            int   Ctr       = 0;

            while (!PeopleStore.EndOfTree())
            {
                Ctr++;
                Person p = PeopleStore.CurrentValue;
                if (p == null)
                {
                    throw new InvalidOperationException("Person record not found.");
                }
                Aids[AidsIndex++] = p.AddressID;
                if (AidsIndex == 1000)
                {
                    //** Do batch Query in set of 1000 Addresses... here we're fully utilizing SOP/disk buffers
                    //** and minimizes file pointer jumps
                    QueryResult <int>[] addressFound;
                    if (AddressStore.Query(QueryExpression <int> .Package(Aids), out addressFound))
                    {
                        foreach (QueryResult <int> v in addressFound)
                        {
                            if (!v.Found)
                            {
                                Console.WriteLine("Address '{0}' not found.", v.Key);
                            }
                        }
                    }
                    AidsIndex = 0;
                }
                if (!PeopleStore.MoveNext())
                {
                    break;
                }
                if (Ctr > PeopleStore.Count + 4)
                {
                    Console.WriteLine("Error... Ctr > People Count.");
                    break;
                }
            }
            if (AidsIndex > 0)
            {
                int[] Aids2 = new int[AidsIndex];
                Array.Copy(Aids, 0, Aids2, 0, AidsIndex);
                QueryResult <int>[] AddressFound;
                if (AddressStore.Query(QueryExpression <int> .Package(Aids2), out AddressFound))
                {
                    foreach (QueryResult <int> v in AddressFound)
                    {
                        if (!v.Found)
                        {
                            Console.WriteLine("Address '{0}' not found.", v.Key);
                        }
                    }
                }
            }
            if (Ctr != PeopleStore.Count)
            {
                Console.WriteLine("Error, count of records doesn't match tree traversal count!");
            }
            else
            {
                Console.WriteLine("{0}: Finished reading {1} records.", DateTime.Now, PeopleStore.Count);
            }
        }