Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 static void ReadRecords(ISortedDictionary <int, Person> store, int MaxCount, string Salt)
 {
     store.MoveFirst();
     store.HintBatchCount = 99;
     for (int i = 0; i < MaxCount; i++)
     {
         Person p = store.CurrentValue;
         if (p == null ||
             p.FirstName != string.Format("Joe{0}{1}", i, Salt))
         {
             Console.WriteLine("Error, data for iteration {0} not found.", i);
         }
         store.MoveNext();
     }
     if (store.EndOfTree())
     {
         Console.WriteLine("Store's End of tree reached.");
     }
 }
Exemplo 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);
            }
        }