internal TableSource CopySourceTable(TableSource tableSource, IIndexSet indexSet) { lock (commitLock) { try { // The unique id that identifies this table, int tableId = NextTableId(); var sourceName = tableSource.SourceName; // Create the object. var masterTable = new TableSource(this, StoreSystem, LargeObjectStore, tableId, sourceName); masterTable.CopyFrom(tableId, tableSource, indexSet); // Add to the list of all tables. tableSources.Add(tableId, masterTable); // Add this to the list of deleted tables, MarkUncommitted(tableId); // Commit this StateStore.Flush(); // And return it. return(masterTable); } catch (IOException e) { throw new Exception(String.Format("Unable to copy source table '{0}' because of an error.", tableSource.TableInfo.TableName), e); } } }
internal void CommitToTables(IEnumerable <int> createdTables, IEnumerable <int> droppedTables) { // Add created tables to the committed tables list. foreach (int createdTable in createdTables) { // For all created tables, add to the visible list and remove from the // delete list in the state store. var t = GetTableSource(createdTable); var resource = new TableStateStore.TableState(t.TableId, t.SourceName); StateStore.AddVisibleResource(resource); StateStore.RemoveDeleteResource(resource.SourceName); } // Remove dropped tables from the committed tables list. foreach (int droppedTable in droppedTables) { // For all dropped tables, add to the delete list and remove from the // visible list in the state store. var t = GetTableSource(droppedTable); var resource = new TableStateStore.TableState(t.TableId, t.SourceName); StateStore.AddDeleteResource(resource); StateStore.RemoveVisibleResource(resource.SourceName); } try { StateStore.Flush(); } catch (IOException e) { throw new InvalidOperationException("IO Error: " + e.Message, e); } }
public void Delete() { lock (commitLock) { // We possibly have things to clean up. CleanUp(); // Go through and delete and close all the committed tables. foreach (var source in tableSources.Values) { source.Drop(); } // Delete the state file StateStore.Flush(); StoreSystem.CloseStore(stateStore); StoreSystem.DeleteStore(stateStore); // Delete the blob store if (LargeObjectStore != null) { StoreSystem.CloseStore(lobStore); StoreSystem.DeleteStore(lobStore); } //tableSources = null; IsClosed = true; } // Release the storage system. StoreSystem.Unlock(StateStoreName); }
private TableSource CreateTableSource(TableInfo tableInfo, bool temporary) { lock (commitLock) { try { int tableId = NextTableId(); // Create the object. var storeSystem = StoreSystem; if (temporary) { storeSystem = tempStoreSystem; } var source = new TableSource(this, storeSystem, LargeObjectStore, tableId, tableInfo.TableName.FullName); source.Create(tableInfo); tableSources.Add(tableId, source); if (!temporary) { MarkUncommitted(tableId); StateStore.Flush(); } // And return it. return(source); } catch (IOException e) { throw new InvalidOperationException(String.Format("Unable to create source for table '{0}'.", tableInfo.TableName), e); } } }
public void Close() { lock (commitLock) { CleanUp(); StoreSystem.SetCheckPoint(); // Go through and close all the committed tables. foreach (var source in tableSources.Values) { source.Close(false); } StateStore.Flush(); StoreSystem.CloseStore(stateStore); //tableSources = null; IsClosed = true; } // Release the storage system StoreSystem.Unlock(StateStoreName); if (LargeObjectStore != null) { StoreSystem.CloseStore(lobStore); } }
private void ReadDroppedTables() { lock (commitLock) { // The list of all dropped tables from the state file var tables = StateStore.GetDeleteList(); // For each visible table foreach (var resource in tables) { int tableId = resource.TableId; string tableName = resource.SourceName; // Load the master table from the resource information var source = LoadTableSource(tableId, tableName); // File wasn't found so remove from the delete resources if (source == null) { StateStore.RemoveDeleteResource(tableName); } else { source.Open(); // Add the table to the table list tableSources.Add(tableId, source); } } StateStore.Flush(); } }
public void Create() { MinimalCreate(); // Initialize the conglomerate system tables. SetupSystem(); // Commit the state StateStore.Flush(); }
public void Create(IEnumerable <ISystemFeature> features) { MinimalCreate(features); // Initialize the conglomerate system tables. SetupSystem(features); // Commit the state StateStore.Flush(); }
private void CleanUp() { lock (commitLock) { if (IsClosed) { return; } // If no open transactions on the database, then clean up. if (Database.OpenTransactions == null || Database.OpenTransactions.Count == 0) { var deleteList = StateStore.GetDeleteList().ToArray(); if (deleteList.Length > 0) { int dropCount = 0; for (int i = deleteList.Length - 1; i >= 0; --i) { var tableName = deleteList[i].SourceName; CloseTable(tableName, true); } for (int i = deleteList.Length - 1; i >= 0; --i) { string tableName = deleteList[i].SourceName; bool dropped = CloseAndDropTable(tableName); // If we managed to drop the table, remove from the list. if (dropped) { StateStore.RemoveDeleteResource(tableName); ++dropCount; } } // If we dropped a table, commit an update to the conglomerate state. if (dropCount > 0) { StateStore.Flush(); } } } } }