public AuditLog_other(StorageTypes storageType, string dbConnStr) { m_storageType = storageType; m_dbConnStr = dbConnStr; m_storageLayer = new StorageLayer(m_storageType, m_dbConnStr); }
public void GlobalSetup() { if (Directory.Exists(_outputFolder)) { Directory.Delete(_outputFolder, true); } Directory.CreateDirectory(_outputFolder); var dbFolder = "D:\\stress"; var dbOptions = new TrimDatabaseOptions(); _cache = dbOptions.BlockCache(); var filenames = Directory.GetFiles(dbFolder); _tableFiles = new TableFile[filenames.Length]; _storageLayer = new SortedStorageLayer(5, _outputFolder, _cache, 10 * 1024 * 1024, 100); for (var i = 0; i < _tableFiles.Length; i++) { var tf = new TableFile(filenames[i], _cache); tf.LoadAsync().Wait(); _tableFiles[i] = tf; } }
public void Handle(StorageLayer layer, Action<FlowProcessingResponse> put) { HandlerHelper.SendStartMessage( "Generating...", FlowProcessingRequestType.GenerateRuntimeBitmap, layer, put); var runtime = this.m_AlgorithmFlowImageGeneration.RegenerateImageForLayer( layer, this.m_CurrentWorldSeedProvider.Seed, this.m_RenderingLocationProvider.X, this.m_RenderingLocationProvider.Y, this.m_RenderingLocationProvider.Z, 64, 64, 64); put(new FlowProcessingResponse { RequestType = FlowProcessingRequestType.GenerateRuntimeBitmap, IsStartNotification = false, Results = new object[] { layer, runtime } }); }
public AnalysisLayer(StorageLayer layer) { AstBuilder astBuilder; var method = DecompileUtil.GetMethodCode(layer.Algorithm.GetType(), out astBuilder, "ProcessCell"); this.Name = layer.Algorithm.GetType().Name; this.Code = method.Body.GetTrackedText(); this.Algorithm = layer.Algorithm; this.AstBuilder = astBuilder; }
public static Bitmap RegenerateImageForLayer(StorageLayer layer, long ox, long oy, long oz, int width, int height, int depth, bool compiled = false) { var runtime = StorageAccess.ToRuntime(layer); //if (compiled) // return Regenerate3DImageForLayer(runtime, ox, oy, oz, width, height, depth, StorageAccess.ToCompiled(layer)); //else return(Regenerate3DImageForLayer(runtime, ox, oy, oz, width, height, depth)); }
public AnalysisLayer(StorageLayer layer) { AstBuilder astBuilder; var method = DecompileUtil.GetAlgorithmCode(layer.Algorithm.GetType(), out astBuilder); this.Name = layer.Algorithm.GetType().Name; this.Code = method.Body.GetTrackedText(); this.Algorithm = layer.Algorithm; this.AstBuilder = astBuilder; }
public Bitmap RegenerateImageForLayer( StorageLayer layer, long seed, long ox, long oy, long oz, int width, int height, int depth, bool compiled = false) { try { var runtime = this.m_StorageAccess.ToRuntime(layer); runtime.SetSeed(seed); if (compiled) { try { return this.m_IsometricBitmapRenderer.GenerateImage( runtime, x => runtime.Algorithm.GetColorForValue(this.m_StorageAccess.FromRuntime(runtime), x), ox, oy, oz, width, height, runtime.Algorithm.Is2DOnly ? 1 : depth); /*return Regenerate3DImageForLayer( runtime, ox, oy, oz, width, height, depth, this.m_StorageAccess.ToCompiled(runtime));*/ } catch (Exception) { return null; } } return this.m_IsometricBitmapRenderer.GenerateImage( runtime, x => runtime.Algorithm.GetColorForValue(this.m_StorageAccess.FromRuntime(runtime), x), ox, oy, oz, width, height, runtime.Algorithm.Is2DOnly ? 1 : depth); } catch (InvalidOperationException) { return null; } }
private int[] ParentsIndexOf(StorageLayer find) { List <int> result = new List <int>(); for (int i = 0; i < this.m_Layer.Inputs.Length; i++) { if (this.m_Layer.Inputs[i] == find) { result.Add(i); } } return(result.ToArray()); }
public AlgorithmFlowElement(FlowInterfaceControl control, StorageLayer l) { this.m_Control = control; this.m_Layer = l; var attrs = l.Algorithm.GetType().GetCustomAttributes(typeof(FlowDesignerNameAttribute), true); this.Name = attrs.Length > 0 ? (attrs[0] as FlowDesignerNameAttribute).Name : l.Algorithm.ToString(); this.ImageWidth = 128; this.ImageHeight = 192; this.ObjectPropertyUpdated(); // Create input / output connectors. foreach (string s in this.m_Layer.Algorithm.InputNames) { this.m_InputConnectors.Add(new AlgorithmFlowConnector(this, s, true, l)); } this.m_OutputConnectors.Add(new AlgorithmFlowConnector(this, "Output", false, l)); this.m_CompiledViewToggleThread = new Thread(() => { while (this.m_CompiledViewToggleThread.ThreadState != ThreadState.AbortRequested) { Thread.Sleep(100); if (this.m_RealBitmap == this.m_RuntimeBitmap) { this.m_RealBitmap = this.m_CompiledBitmap; } else { this.m_RealBitmap = this.m_RuntimeBitmap; } try { this.m_Control.Invoke(new Action(() => { this.m_Control.Invalidate(this.InvalidatingRegion.Apply(this.m_Control.Zoom)); })); } catch { break; } } }); this.m_CompiledViewToggleThread.Start(); }
public AlgorithmFlowElement( FlowInterfaceControl control, IFlowProcessingPipeline processingPipeline, StorageLayer l) { this.m_Control = control; this.m_FlowProcessingPipeline = processingPipeline; this.m_Layer = l; var attrs = l.Algorithm.GetType().GetCustomAttributes(typeof(FlowDesignerNameAttribute), true); this.Name = attrs.Length > 0 ? (attrs[0] as FlowDesignerNameAttribute).Name : l.Algorithm.ToString(); this.ImageWidth = 128; this.ImageHeight = 192; this.ObjectPropertyUpdated(); // Create input / output connectors. foreach (string s in this.m_Layer.Algorithm.InputNames) this.m_InputConnectors.Add(new AlgorithmFlowConnector(this, s, true, l)); this.m_OutputConnectors.Add(new AlgorithmFlowConnector(this, "Output", false, l)); /*this.m_CompiledViewToggleThread = new Thread(() => { while (this.m_CompiledViewToggleThread.ThreadState != ThreadState.AbortRequested) { Thread.Sleep(100); if (this.m_RealBitmap == this.m_RuntimeBitmap) this.m_RealBitmap = this.m_CompiledBitmap; else this.m_RealBitmap = this.m_RuntimeBitmap; try { this.m_Control.Invoke(new Action(() => { this.m_Control.Invalidate(this.InvalidatingRegion.Apply(this.m_Control.Zoom)); })); } catch { break; } } }); this.m_CompiledViewToggleThread.Start();*/ }
public static void SendStartMessage( string message, FlowProcessingRequestType type, StorageLayer layer, Action<FlowProcessingResponse> put) { var info = new Bitmap( 128, message.Split(new[] { "\r\n" }, StringSplitOptions.None).Length * 16); var graphics = Graphics.FromImage(info); var font = new Font(SystemFonts.DefaultFont, FontStyle.Bold); var brush = new SolidBrush(Color.White); graphics.Clear(Color.Black); graphics.DrawString(message, font, brush, new PointF(0, 0)); put(new FlowProcessingResponse { RequestType = type, IsStartNotification = true, Results = new object[] { layer, info } }); }
private void RestoreNotFinishedTransactions() { //TODO Trie settings from the table must be taken from schema (when they will differ) //STORE FILE NAME of rollback not table name try { byte[] btCommittedTablesNames = null; List <string> committedTablesNames = new List <string>(); if (LTrie.Count(false) == 0) //All ok { LTrie.RemoveAll(true); return; } string physicalPathToTheUserTable = String.Empty; //Settigns and storage for Committed tables !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MUST BE TAKEN FROM SCHEMA, FOR NOW DEFAULT TrieSettings ltrSet = null; IStorage storage = null; DBriize.LianaTrie.LTrie ltrie = null; foreach (var row in LTrie.IterateForward(true, false)) { btCommittedTablesNames = row.GetFullValue(true); committedTablesNames = System.Text.Encoding.UTF8.GetString(btCommittedTablesNames).DeserializeXml <List <string> >(); foreach (var fn in committedTablesNames) { //Trying to get path from the Schema, there is universal function for getting table physical TABLE FULL PATH /NAME physicalPathToTheUserTable = Engine.DBriizeSchema.GetPhysicalPathToTheUserTable(fn); //Returned path can be empty, if no more such table if (physicalPathToTheUserTable == String.Empty) { continue; } //We don't restore in-memory tables if (physicalPathToTheUserTable == "MEMORY") { continue; } //we open ltrie, and it automatically restores rollback ltrSet = new TrieSettings(); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MUST BE TAKEN FROM SCHEMA, FOR NOW DEFAULT //storage = new TrieDiskStorage(physicalPathToTheUserTable, ltrSet, Engine.Configuration); storage = new StorageLayer(physicalPathToTheUserTable, ltrSet, Engine.Configuration); ltrie = new LTrie(storage); //closing trie, that Schema could open it again ltrie.Dispose(); ////Deleting rollback file for such table //physicalPathToTheUserTable += ".rol"; //System.IO.File.Delete(physicalPathToTheUserTable); } committedTablesNames.Clear(); } //If all ok, recreate file LTrie.RemoveAll(true); } catch (OperationCanceledException ex) { throw ex; } //catch (System.Threading.ThreadAbortException ex) //{ // //We don'T make DBisOperable = false; // throw ex; //} catch (Exception) { //BRINGS TO DB NOT OPERATABLE this.Engine.DBisOperable = false; this.Engine.DBisOperableReason = "TransactionsCoordinator.RestoreNotFinishedTransaction"; //NOT CASCADE ADD EXCEPTION throw DBriizeException.Throw(DBriizeException.eDBriizeExceptions.CLEAN_ROLLBACK_FILES_FOR_FINISHED_TRANSACTIONS_FAILED); } }
private int[] ParentsIndexOf(StorageLayer find) { var result = new List<int>(); for (var i = 0; i < this.m_Layer.Inputs.Length; i++) if (this.m_Layer.Inputs[i] == find) result.Add(i); return result.ToArray(); }
public HealthController(StorageLayer storageLayer) { _storageLayer = storageLayer; }
public void Handle(StorageLayer layer, Action<FlowProcessingResponse> put) { HandlerHelper.SendStartMessage( "Performance\r\ntesting...", FlowProcessingRequestType.GenerateRuntimeBitmap, layer, put); // Settings. var testTime = 50; var warningLimit = 5000; // 5ms var badLimit = 16000; // 16ms // Perform conversions. var runtime = this.m_StorageAccess.ToRuntime(layer); runtime.SetSeed(this.m_CurrentWorldSeedProvider.Seed); IGenerator compiled = null; try { compiled = this.m_StorageAccess.ToCompiled(runtime); } catch (Exception) { // Failed to compile layer. } // First check how many iterations of 8x8x8 generation the runtime layer can do in the test time. var runtimeStart = DateTime.Now; var runtimeComputations = 0; var iterations = 0; while ((DateTime.Now - runtimeStart).TotalMilliseconds < testTime) { runtime.GenerateData(0, 0, 0, 32, 32, 32, out runtimeComputations); iterations++; } var runtimeEnd = DateTime.Now; // Now check how long it takes the compiled layer to do as many iterations of generating 8x8x8. var compiledStart = DateTime.Now; var compiledComputations = 0; if (compiled != null) { try { for (var i = 0; i < iterations; i++) compiled.GenerateData(0, 0, 0, 32, 32, 32, out compiledComputations); } catch { compiled = null; } } var compiledEnd = DateTime.Now; // Determine the per-operation cost. var runtimeCost = runtimeEnd - runtimeStart; var compiledCost = compiledEnd - compiledStart; var runtimeus = Math.Round((runtimeCost.TotalMilliseconds / iterations) * 1000, 0); // Microseconds. var compiledus = Math.Round((compiledCost.TotalMilliseconds / iterations) * 1000, 0); // Define colors and determine values. var okay = new SolidBrush(Color.LightGreen); var warning = new SolidBrush(Color.Orange); var bad = new SolidBrush(Color.IndianRed); var runtimeColor = okay; var compiledColor = okay; if (runtimeus > warningLimit) runtimeColor = warning; if (compiledus > warningLimit) compiledColor = warning; if (runtimeus > badLimit) runtimeColor = bad; if (compiledus > badLimit) compiledColor = bad; // Draw performance measurements. Bitmap bitmap; if (runtimeComputations != compiledComputations && compiled != null) bitmap = new Bitmap(128, 48); else bitmap = new Bitmap(128, 32); var graphics = Graphics.FromImage(bitmap); var font = new Font(SystemFonts.DefaultFont, FontStyle.Bold); graphics.Clear(Color.Black); if (runtimeComputations != compiledComputations && compiled != null) { graphics.DrawString("Computation mismatch!", font, bad, new PointF(0, 0)); graphics.DrawString("Runtime:", font, runtimeColor, new PointF(0, 16)); graphics.DrawString(runtimeComputations + "c", font, runtimeColor, new PointF(70, 16)); if (compiled != null) { graphics.DrawString("Compiled:", font, compiledColor, new PointF(0, 32)); graphics.DrawString(compiledComputations + "c", font, compiledColor, new PointF(70, 32)); } else graphics.DrawString("Unable to compile.", font, bad, new PointF(0, 32)); } else { graphics.DrawString("Runtime:", font, runtimeColor, new PointF(0, 0)); graphics.DrawString(runtimeus + "\xB5s", font, runtimeColor, new PointF(70, 0)); if (compiled != null) { graphics.DrawString("Compiled:", font, compiledColor, new PointF(0, 16)); graphics.DrawString(compiledus + "\xB5s", font, compiledColor, new PointF(70, 16)); } else graphics.DrawString("Unable to compile.", font, bad, new PointF(0, 16)); } var additionalInformation = bitmap; Bitmap compiledBitmap = null; // Use the compiled layer to re-render the output. if (compiled != null) { compiledBitmap = this.m_AlgorithmFlowImageGeneration.RegenerateImageForLayer( layer, this.m_CurrentWorldSeedProvider.Seed, this.m_RenderingLocationProvider.X, this.m_RenderingLocationProvider.Y, this.m_RenderingLocationProvider.Z, 64, 64, 64, true); } put(new FlowProcessingResponse { RequestType = FlowProcessingRequestType.GeneratePerformanceResults, IsStartNotification = false, Results = new object[] { layer, additionalInformation, compiledBitmap } }); }
public AlgorithmFlowConnector(AlgorithmFlowElement owner, string name, bool isInput, StorageLayer layer) : base(owner, name, isInput) { this.m_LayerOwner = owner; }
/// <summary> /// Returns table for READ, WRITE FUNC /// </summary> /// <param name="userTableName"></param> /// <returns></returns> internal LTrie GetTable(string userTableName) { string tableName = GetUserTableNameAsString(userTableName); //TODO pattern based mapping If table doesn't exist we create it with properties which could be supplied after db init as regex theme. //Schema protocol: 2 bytes - protocol version, other data //For protocol 1: first 8 bytes will be TheFileName, starting from db10000-dbN (0-N ulong). up to 10000 are reserved for dbreeze. //Table names are UTF-8 based, no limits ulong fileName = 0; OpenTable otl = null; _sync_openTablesHolder.EnterUpgradeableReadLock(); try { _openTablesHolder.TryGetValue(tableName, out otl); if (otl != null) { //Try to increase usage and return LTrie otl.Add(); return(otl.Trie); } //Probably table Exists in db but not in openTablesHolder _sync_openTablesHolder.EnterWriteLock(); try { //UpgradeableRead recheck _openTablesHolder.TryGetValue(tableName, out otl); if (otl != null) { //Try to increase usage and return LTrie otl.Add(); return(otl.Trie); } byte[] btTableName = GetUserTableNameAsByte(userTableName); //Trying to get fileName from cache fileName = this.cachedTableNames.GetFileName(tableName); // LTrieRow row = null; bool tableExists = false; if (fileName == 0) { LTrieRow row = LTrie.GetKey(btTableName, false, false); if (row.Exists) { tableExists = true; byte[] fullValue = row.GetFullValue(false); //Can be parsed different. First protocol version is 1 ushort schemeProtocol = fullValue.Substring(0, 2).To_UInt16_BigEndian(); switch (schemeProtocol) { case 1: fileName = fullValue.Substring(2, 8).To_UInt64_BigEndian(); break; default: throw DBreezeException.Throw(DBreezeException.eDBreezeExceptions.SCHEME_FILE_PROTOCOL_IS_UNKNOWN); } } else { tableExists = false; //Creating new table. //Checking table name validity //this will throw exception, if not valid DbUserTables.UserTableNameIsOk(userTableName); //Creating such table and renewing LastFileNumber counter //Adding to LastFileNumber LastFileNumber++; ////Deleting physical files related to the table, if they existed - normally they should not //DeleteAllReleatedTableFiles(Path.Combine(Engine.MainFolder, LastFileNumber.ToString())); byte[] lft = LastFileNumber.To_8_bytes_array_BigEndian(); //Writing this number to Schema file LTrie.Add(Encoding.UTF8.GetBytes(LastFileNumberKeyName), lft); //Creating table self and writing to Schema file LTrie.Add(btTableName, new byte[] { 0, 1 } //Protocol version 1 .Concat(lft)); //Number of the file //Committing both records LTrie.Commit(); fileName = LastFileNumber; this.cachedTableNames.Add(tableName, fileName); } } else { tableExists = true; } //Creating LTrie, adding it to _openTablesHolder //Seeting up Trie TableName, OTHER SETTINGS TrieSettings ts = new TrieSettings(); IStorage storage = null; ////Checking if default Flusg Disk behaviour was overriden //ts.DiskFlushBehaviour = Engine.Configuration.DiskFlushBehaviour; ////Checking if we have alternative DiskFlush behaviour //foreach (var pattern in Engine.Configuration.AlternativeDiskFlushBehaviour) //{ // //pattern.Key // if (DbUserTables.PatternsIntersect(pattern.Key, userTableName)) // { // ts.DiskFlushBehaviour = pattern.Value; // break; // } //} string alternativeTableLocation = String.Empty; if (CheckAlternativeTableLocationsIntersections(userTableName, out alternativeTableLocation)) { ts.StorageWasOverriden = true; if (alternativeTableLocation == String.Empty) { ts.AlternativeTableStorageType = DBreezeConfiguration.eStorage.MEMORY; storage = new StorageLayer(Path.Combine(Engine.MainFolder, fileName.ToString()), ts, Engine.Configuration); } else { ts.AlternativeTableStorageType = DBreezeConfiguration.eStorage.DISK; ts.AlternativeTableStorageFolder = alternativeTableLocation; DirectoryInfo diAlt = new DirectoryInfo(alternativeTableLocation); if (!diAlt.Exists) { diAlt.Create(); } if (!tableExists) { //Deleting physical files related to the table, if they existed - normally they should not DeleteAllReleatedTableFiles(Path.Combine(ts.AlternativeTableStorageFolder, LastFileNumber.ToString())); } storage = new StorageLayer(Path.Combine(ts.AlternativeTableStorageFolder, fileName.ToString()), ts, Engine.Configuration); } } else { if (!tableExists) { //Deleting physical files related to the table, if they existed - normally they should not DeleteAllReleatedTableFiles(Path.Combine(Engine.MainFolder, LastFileNumber.ToString())); } storage = new StorageLayer(Path.Combine(Engine.MainFolder, fileName.ToString()), ts, Engine.Configuration); } //storage = new StorageLayer(Path.Combine(Engine.MainFolder, fileName.ToString()), ts, Engine.Configuration); LTrie trie = new LTrie(storage); //Setting LTrie user table name trie.TableName = userTableName; //_openTablesHolder.Add(tableName, trie); //Automatically increased usage in OpenTable constructor _openTablesHolder.Add(tableName, new OpenTable(trie)); return(trie); } catch (System.Exception ex) { //CASCADE throw ex; } finally { _sync_openTablesHolder.ExitWriteLock(); } } catch (Exception ex) { throw DBreezeException.Throw(DBreezeException.eDBreezeExceptions.SCHEME_GET_TABLE_WRITE_FAILED, tableName, ex); } finally { _sync_openTablesHolder.ExitUpgradeableReadLock(); } }