diff --git a/Src/DSInternals.DataStore/DirectorySchema.cs b/Src/DSInternals.DataStore/DirectorySchema.cs index 1a956e9..468f62e 100644 --- a/Src/DSInternals.DataStore/DirectorySchema.cs +++ b/Src/DSInternals.DataStore/DirectorySchema.cs @@ -8,6 +8,7 @@ using Microsoft.Database.Isam; using DSInternals.Common; using DSInternals.Common.Exceptions; + using Microsoft.Isam.Esent.Interop; /// /// The ActiveDirectorySchema class represents the schema partition for a particular domain. @@ -30,7 +31,7 @@ { TableDefinition dataTable = database.Tables[ADConstants.DataTableName]; this.LoadColumnList(dataTable.Columns); - this.LoadAttributeIndices(dataTable.Indices); + this.LoadAttributeIndices(dataTable.Indices2); using (var cursor = database.OpenCursor(ADConstants.DataTableName)) { this.LoadClassList(cursor); @@ -128,15 +129,19 @@ } } - private void LoadAttributeIndices(IndexCollection indices) + private void LoadAttributeIndices(IEnumerable indices) { - foreach (IndexDefinition index in indices) + //HACK: We are using low-level IndexInfo instead of high-level IndexCollection. + /* There is a bug in Isam IndexCollection enumerator, which causes it to loop indefinitely + * through the first few indices under some very rare circumstances. */ + foreach (var index in indices) { - if (index.KeyColumns.Count == 1) + var segments = index.IndexSegments; + if (segments.Count == 1) { // We support only simple indexes SchemaAttribute attr = FindAttributeByIndexName(index.Name); - if(attr != null) + if (attr != null) { // We found a single attribute to which this index corresponds attr.Index = index.Name; diff --git a/Src/Microsoft.Database.Isam/TableDefinition.cs b/Src/Microsoft.Database.Isam/TableDefinition.cs index 79aa507..8b25a83 100644 --- a/Src/Microsoft.Database.Isam/TableDefinition.cs +++ b/Src/Microsoft.Database.Isam/TableDefinition.cs @@ -12,6 +12,7 @@ namespace Microsoft.Database.Isam { using Microsoft.Isam.Esent.Interop; + using System.Collections.Generic; /// /// A Table Definition contains the schema for a single table. It can be @@ -126,6 +127,21 @@ namespace Microsoft.Database.Isam } } + /// + /// Gets a collection containing the tables indices. + /// + public IEnumerable Indices2 + { + //HACK: We added support to retrieve the low-level IndexInfo instead of high-level IndexCollection. + /* There is a bug in Isam IndexCollection enumerator, which causes it to loop indefinitely + * through the first few indices under some very rare circumstances. */ + get + { + // TODO: Possibly add a lock for thread safety. + return Api.GetTableIndexes(this.IsamSession.Sesid, this.Database.Dbid, this.Name); + } + } + /// /// Gets the session. ///