public SqlSession(Mode mode) { this.mode = mode; commitMode = (mode == Mode.AUTO_COMMIT || mode == Mode.READ_ONLY ? Mode.AUTO_COMMIT : Mode.TRANSACTIONAL); //commitMode = (mode == Mode.TRANSACTIONAL ? mode : Mode.AUTO_COMMIT); commsMode = (mode == Mode.BATCH ? CommunicationMode.SQL : globalCommsMode); if (mode == Mode.BATCH && batch == null) { batch = new List<DataRow>(); } BatchTable = new Dictionary<String, DataTable>(8); // if there is an existing session, then make it our parent parent = current.Value; //session = new SqlSession(mode); current.Value = this; sessions.TryAdd(this, Thread.CurrentThread.Name); //return session; }
public void run() { Stopwatch timer = ctrl.wallTimer; long start = timer.ElapsedTicks; long workStart = start; long workTime = 0; long ownerId; long eventId; long groupId; int total = 0; //appLog.log("starting generation - getting first session..."); using (SqlSession session = new SqlSession(SqlSession.Mode.TRANSACTIONAL)) { for (int retry = 0; ; retry++) { try { Owner owner = generateOwner(); ownerId = insertOwner(ref owner); Console.Out.WriteLine("\n------------------------------------------------"); report("Owner", 1, timer.ElapsedTicks - start); Event ev = generateEvent(ownerId); eventId = insertEvent(ref ev); workTime += timer.ElapsedTicks - workStart; int groupCount = ctrl.minGroups + ctrl.random.Next(ctrl.maxGroups - ctrl.minGroups); appLog.info("Creating {0} groups", groupCount); total = 2 + groupCount; // data records per group int dataCount = (ctrl.minData + ctrl.random.Next(ctrl.maxData - ctrl.minData)) / groupCount; appLog.info("Creating {0} Data records @ {1} records per group", dataCount * groupCount, dataCount); workStart = timer.ElapsedTicks; for (int gx = 0; gx < groupCount; gx++) { Group group = generateGroup(eventId, gx); appLog.info("group= {0}", group.GroupGuid); groupId = insertGroup(ref group); total += dataCount; long dataStart = timer.ElapsedTicks; insertDataForGroup(ref group, dataCount); report("Data Group", dataCount, timer.ElapsedTicks - dataStart); } break; // work complete } catch (Exception e) { appLog.info("Error inserting data for run {0}:\n\t{1}", unique, e.ToString()); if (session.retry(e) && retry < ctrl.maxRetry) { appLog.info("Retrying..."); try { Thread.Sleep(ctrl.retrySleep * (retry + 1)); } catch (Exception) { } continue; } throw new PersistenceException("Permanent error after {0} retries", retry); } } } // commit the enclosing tx //timer.Stop(); long duration = timer.ElapsedTicks - start; report("All Data", total, duration); //totalInserts += total; //totalInsertTime += duration; Interlocked.Add(ref ctrl.totalInserts, total); Interlocked.Add(ref ctrl.totalInsertTime, duration); ctrl.scheduleViewTask(eventId); }
/** * perform any logic required after configuration, and before the Controller can be used */ public void init() { if (initDb) { initializeDatabase(); unique = 1; } else { using (SqlSession session = new SqlSession(SqlSession.Mode.AUTO_COMMIT)) { //String lastEventId = eventRepository.getValue("id", "ORDER BY id DESC LIMIT 1"); //unique = Int64.Parse(lastEventId) + 1; unique = 100000; appLog.info("lastEventID = {0}", unique-1); } } }
protected void initializeDatabase() { String script; if (!appProperties.TryGetValue(DB_INIT_SQL, out script)) appLog.log("Somehow script is NULL"); appLog.info("running init sql (length: {0}): {1}", script.Length, script); using (SqlSession session = new SqlSession(SqlSession.Mode.AUTO_COMMIT)) { session.execute(script); } }
public void run() { //long x = totalInserts; Controller.viewLog.info("Running view query for event {0}", eventId); Stopwatch timer = ctrl.wallTimer; try { using (SqlSession session = new SqlSession(SqlSession.Mode.READ_ONLY)) { long start = timer.ElapsedTicks; EventDetails details = ctrl.eventRepository.getDetails(eventId); long duration = timer.ElapsedTicks - start; if (details != null) { Interlocked.Increment(ref ctrl.totalQueries); Interlocked.Add(ref ctrl.totalQueryRecords, details.Data.Count()); Interlocked.Add(ref ctrl.totalQueryTime, duration); Controller.appLog.info("Event viewed. Query response time= {0:F3} secs; {1:N} Data objects attached in {2} groups.", (duration / Stopwatch.Frequency), details.Data.Count(), details.Groups.Count()); } } } catch (PersistenceException e) { Controller.viewLog.info("Error retrieving Event: {0}", e.ToString()); //e.printStackTrace(System.out); Controller.viewLog.log(e.StackTrace.ToString()); } //int queueSize = ((ThreadPoolExecutor) ctrl.insertExecutor).getQueue().size(); //long queueSize = ctrl.totalScheduled - ctrl.totalInserts; long queueSize = ctrl.insertExecutor.QueueSize(); if (ctrl.queryBackoff > 0 && queueSize > ctrl.maxQueued) { Controller.appLog.info("(query) Queue size > maxQueued ({0}); sleeping for {1} ms...", ctrl.maxQueued, ctrl.queryBackoff); Thread.Sleep(ctrl.queryBackoff); } }