提交 4efd4762 编写于 作者: S Shuduo Sang

fix autopep8 format.

上级 2d02ee85
...@@ -1385,15 +1385,18 @@ class Task(): ...@@ -1385,15 +1385,18 @@ class Task():
try: try:
self._executeInternal(te, wt) # TODO: no return value? self._executeInternal(te, wt) # TODO: no return value?
except taos.error.ProgrammingError as err: except taos.error.ProgrammingError as err:
errno2 = err.errno if (err.errno > 0) else 0x80000000 + err.errno # correct error scheme errno2 = err.errno if (
if ( errno2 in [ err.errno > 0) else 0x80000000 + err.errno # correct error scheme
if (errno2 in [
0x05, # TSDB_CODE_RPC_NOT_READY 0x05, # TSDB_CODE_RPC_NOT_READY
0x200, 0x360, 0x362, 0x36A, 0x36B, 0x36D, 0x381, 0x380, 0x383, 0x503, 0x200, 0x360, 0x362, 0x36A, 0x36B, 0x36D, 0x381, 0x380, 0x383, 0x503,
0x510, # vnode not in ready state 0x510, # vnode not in ready state
0x600, 0x600,
1000 # REST catch-all error 1000 # REST catch-all error
]) : # allowed errors ]): # allowed errors
self.logDebug("[=] Acceptable Taos library exception: errno=0x{:X}, msg: {}, SQL: {}".format(errno2, err, self._lastSql)) self.logDebug(
"[=] Acceptable Taos library exception: errno=0x{:X}, msg: {}, SQL: {}".format(
errno2, err, self._lastSql))
print("_", end="", flush=True) print("_", end="", flush=True)
self._err = err self._err = err
else: else:
...@@ -1862,6 +1865,7 @@ class MyLoggingAdapter(logging.LoggerAdapter): ...@@ -1862,6 +1865,7 @@ class MyLoggingAdapter(logging.LoggerAdapter):
return "[{}]{}".format(threading.get_ident() % 10000, msg), kwargs return "[{}]{}".format(threading.get_ident() % 10000, msg), kwargs
# return '[%s] %s' % (self.extra['connid'], msg), kwargs # return '[%s] %s' % (self.extra['connid'], msg), kwargs
class SvcManager: class SvcManager:
MAX_QUEUE_SIZE = 10000 MAX_QUEUE_SIZE = 10000
...@@ -1873,35 +1877,39 @@ class SvcManager: ...@@ -1873,35 +1877,39 @@ class SvcManager:
self.ioThread = None self.ioThread = None
self.subProcess = None self.subProcess = None
self.shouldStop = False self.shouldStop = False
# self.status = MainExec.STATUS_RUNNING # set inside _startTaosService() # self.status = MainExec.STATUS_RUNNING # set inside
# _startTaosService()
def svcOutputReader(self, out: IO, queue): def svcOutputReader(self, out: IO, queue):
# Important Reference: https://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python # Important Reference:
# https://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python
print("This is the svcOutput Reader...") print("This is the svcOutput Reader...")
# for line in out : # for line in out :
for line in iter(out.readline, b''): for line in iter(out.readline, b''):
# print("Finished reading a line: {}".format(line)) # print("Finished reading a line: {}".format(line))
# print("Adding item to queue...") # print("Adding item to queue...")
line = line.decode("utf-8").rstrip() line = line.decode("utf-8").rstrip()
queue.put(line) # This might block, and then causing "out" buffer to block # This might block, and then causing "out" buffer to block
queue.put(line)
print("_i", end="", flush=True) print("_i", end="", flush=True)
# Trim the queue if necessary # Trim the queue if necessary
oneTenthQSize = self.MAX_QUEUE_SIZE // 10 oneTenthQSize = self.MAX_QUEUE_SIZE // 10
if (queue.qsize() >= (self.MAX_QUEUE_SIZE - oneTenthQSize) ) : # 90% full? if (queue.qsize() >= (self.MAX_QUEUE_SIZE - oneTenthQSize)): # 90% full?
print("Triming IPC queue by: {}".format(oneTenthQSize)) print("Triming IPC queue by: {}".format(oneTenthQSize))
for i in range(0, oneTenthQSize) : for i in range(0, oneTenthQSize):
try: try:
queue.get_nowait() queue.get_nowait()
except Empty: except Empty:
break # break out of for loop, no more trimming break # break out of for loop, no more trimming
if self.shouldStop : if self.shouldStop:
print("Stopping to read output from sub process") print("Stopping to read output from sub process")
break break
# queue.put(line) # queue.put(line)
print("\nNo more output (most likely) from IO thread managing TDengine service") # meaning sub process must have died # meaning sub process must have died
print("\nNo more output (most likely) from IO thread managing TDengine service")
out.close() out.close()
def _doMenu(self): def _doMenu(self):
...@@ -1923,19 +1931,21 @@ class SvcManager: ...@@ -1923,19 +1931,21 @@ class SvcManager:
choice = "" # reset choice = "" # reset
return choice return choice
def sigUsrHandler(self, signalNumber, frame) : def sigUsrHandler(self, signalNumber, frame):
print("Interrupting main thread execution upon SIGUSR1") print("Interrupting main thread execution upon SIGUSR1")
if self.status != MainExec.STATUS_RUNNING : if self.status != MainExec.STATUS_RUNNING:
print("Ignoring repeated SIG...") print("Ignoring repeated SIG...")
return # do nothing if it's already not running return # do nothing if it's already not running
self.status = MainExec.STATUS_STOPPING self.status = MainExec.STATUS_STOPPING
choice = self._doMenu() choice = self._doMenu()
if choice == "1" : if choice == "1":
self.sigHandlerResume() # TODO: can the sub-process be blocked due to us not reading from queue? # TODO: can the sub-process be blocked due to us not reading from
elif choice == "2" : # queue?
self.sigHandlerResume()
elif choice == "2":
self.stopTaosService() self.stopTaosService()
elif choice == "3" : elif choice == "3":
self.stopTaosService() self.stopTaosService()
self.startTaosService() self.startTaosService()
else: else:
...@@ -1943,7 +1953,7 @@ class SvcManager: ...@@ -1943,7 +1953,7 @@ class SvcManager:
def sigIntHandler(self, signalNumber, frame): def sigIntHandler(self, signalNumber, frame):
print("Sig INT Handler starting...") print("Sig INT Handler starting...")
if self.status != MainExec.STATUS_RUNNING : if self.status != MainExec.STATUS_RUNNING:
print("Ignoring repeated SIG_INT...") print("Ignoring repeated SIG_INT...")
return return
...@@ -1951,7 +1961,7 @@ class SvcManager: ...@@ -1951,7 +1961,7 @@ class SvcManager:
self.stopTaosService() self.stopTaosService()
print("INT signal handler returning...") print("INT signal handler returning...")
def sigHandlerResume(self) : def sigHandlerResume(self):
print("Resuming TDengine service manager thread (main thread)...\n\n") print("Resuming TDengine service manager thread (main thread)...\n\n")
self.status = MainExec.STATUS_RUNNING self.status = MainExec.STATUS_RUNNING
...@@ -1959,18 +1969,20 @@ class SvcManager: ...@@ -1959,18 +1969,20 @@ class SvcManager:
if self.ioThread: if self.ioThread:
self.ioThread.join() self.ioThread.join()
self.ioThread = None self.ioThread = None
else : else:
print("Joining empty thread, doing nothing") print("Joining empty thread, doing nothing")
TD_READY_MSG = "TDengine is initialized successfully" TD_READY_MSG = "TDengine is initialized successfully"
def _procIpcBatch(self): def _procIpcBatch(self):
# Process all the output generated by the underlying sub process, managed by IO thread # Process all the output generated by the underlying sub process,
while True : # managed by IO thread
while True:
try: try:
line = self.ipcQueue.get_nowait() # getting output at fast speed line = self.ipcQueue.get_nowait() # getting output at fast speed
print("_o", end="", flush=True) print("_o", end="", flush=True)
if self.status == MainExec.STATUS_STARTING : # we are starting, let's see if we have started if self.status == MainExec.STATUS_STARTING: # we are starting, let's see if we have started
if line.find(self.TD_READY_MSG) != -1 : # found if line.find(self.TD_READY_MSG) != -1: # found
self.status = MainExec.STATUS_RUNNING self.status = MainExec.STATUS_RUNNING
except Empty: except Empty:
...@@ -1981,13 +1993,14 @@ class SvcManager: ...@@ -1981,13 +1993,14 @@ class SvcManager:
print(line) print(line)
def _procIpcAll(self): def _procIpcAll(self):
while True : while True:
print("<", end="", flush=True) print("<", end="", flush=True)
self._procIpcBatch() # process one batch self._procIpcBatch() # process one batch
# check if the ioThread is still running # check if the ioThread is still running
if (not self.ioThread) or (not self.ioThread.is_alive()): if (not self.ioThread) or (not self.ioThread.is_alive()):
print("IO Thread (with subprocess) has ended, main thread now exiting...") print(
"IO Thread (with subprocess) has ended, main thread now exiting...")
self.stopTaosService() self.stopTaosService()
self._procIpcBatch() # one more batch self._procIpcBatch() # one more batch
return # TODO: maybe one last batch? return # TODO: maybe one last batch?
...@@ -2024,7 +2037,7 @@ class SvcManager: ...@@ -2024,7 +2037,7 @@ class SvcManager:
svcCmd = [taosdPath, '-c', cfgPath] svcCmd = [taosdPath, '-c', cfgPath]
# svcCmd = ['vmstat', '1'] # svcCmd = ['vmstat', '1']
if self.subProcess : # already there if self.subProcess: # already there
raise RuntimeError("Corrupt process state") raise RuntimeError("Corrupt process state")
self.subProcess = subprocess.Popen( self.subProcess = subprocess.Popen(
...@@ -2034,9 +2047,11 @@ class SvcManager: ...@@ -2034,9 +2047,11 @@ class SvcManager:
close_fds=ON_POSIX) # had text=True, which interferred with reading EOF close_fds=ON_POSIX) # had text=True, which interferred with reading EOF
self.ipcQueue = Queue() self.ipcQueue = Queue()
if self.ioThread : if self.ioThread:
raise RuntimeError("Corrupt thread state") raise RuntimeError("Corrupt thread state")
self.ioThread = threading.Thread(target=self.svcOutputReader, args=(self.subProcess.stdout, self.ipcQueue)) self.ioThread = threading.Thread(
target=self.svcOutputReader, args=(
self.subProcess.stdout, self.ipcQueue))
self.ioThread.daemon = True # thread dies with the program self.ioThread.daemon = True # thread dies with the program
self.ioThread.start() self.ioThread.start()
...@@ -2044,30 +2059,36 @@ class SvcManager: ...@@ -2044,30 +2059,36 @@ class SvcManager:
self.status = MainExec.STATUS_STARTING self.status = MainExec.STATUS_STARTING
# wait for service to start # wait for service to start
for i in range(0, 10) : for i in range(0, 10):
time.sleep(1.0) time.sleep(1.0)
self._procIpcBatch() # pump messages self._procIpcBatch() # pump messages
print("_zz_", end="", flush=True) print("_zz_", end="", flush=True)
if self.status == MainExec.STATUS_RUNNING : if self.status == MainExec.STATUS_RUNNING:
print("TDengine service READY to process requests") print("TDengine service READY to process requests")
return # now we've started return # now we've started
raise RuntimeError("TDengine service did not start successfully") # TODO: handle this better? # TODO: handle this better?
raise RuntimeError("TDengine service did not start successfully")
def stopTaosService(self): def stopTaosService(self):
# can be called from both main thread or signal handler # can be called from both main thread or signal handler
print("Terminating TDengine service running as the sub process...") print("Terminating TDengine service running as the sub process...")
# Linux will send Control-C generated SIGINT to the TDengine process already, ref: https://unix.stackexchange.com/questions/176235/fork-and-how-signals-are-delivered-to-processes # Linux will send Control-C generated SIGINT to the TDengine process
if not self.subProcess : # already, ref:
# https://unix.stackexchange.com/questions/176235/fork-and-how-signals-are-delivered-to-processes
if not self.subProcess:
print("Process already stopped") print("Process already stopped")
return return
retCode = self.subProcess.poll() retCode = self.subProcess.poll()
if retCode : # valid return code, process ended if retCode: # valid return code, process ended
self.subProcess = None self.subProcess = None
else: # process still alive, let's interrupt it else: # process still alive, let's interrupt it
print("Sub process still running, sending SIG_INT and waiting for it to stop...") print(
self.subProcess.send_signal(signal.SIGINT) # sub process should end, then IPC queue should end, causing IO thread to end "Sub process still running, sending SIG_INT and waiting for it to stop...")
try : # sub process should end, then IPC queue should end, causing IO
# thread to end
self.subProcess.send_signal(signal.SIGINT)
try:
self.subProcess.wait(10) self.subProcess.wait(10)
except subprocess.TimeoutExpired as err: except subprocess.TimeoutExpired as err:
print("Time out waiting for TDengine service process to exit") print("Time out waiting for TDengine service process to exit")
...@@ -2076,7 +2097,9 @@ class SvcManager: ...@@ -2076,7 +2097,9 @@ class SvcManager:
self.subProcess = None self.subProcess = None
if self.subProcess and (not self.subProcess.poll()): if self.subProcess and (not self.subProcess.poll()):
print("Sub process is still running... pid = {}".format(self.subProcess.pid)) print(
"Sub process is still running... pid = {}".format(
self.subProcess.pid))
self.shouldStop = True self.shouldStop = True
self.joinIoThread() self.joinIoThread()
...@@ -2148,7 +2171,7 @@ class ClientManager: ...@@ -2148,7 +2171,7 @@ class ClientManager:
self._printLastNumbers() self._printLastNumbers()
def run(self): def run(self):
if gConfig.auto_start_service : if gConfig.auto_start_service:
svcMgr = SvcManager() svcMgr = SvcManager()
svcMgr.startTaosService() svcMgr.startTaosService()
...@@ -2163,7 +2186,7 @@ class ClientManager: ...@@ -2163,7 +2186,7 @@ class ClientManager:
# print("exec stats: {}".format(self.tc.getExecStats())) # print("exec stats: {}".format(self.tc.getExecStats()))
# print("TC failed = {}".format(self.tc.isFailed())) # print("TC failed = {}".format(self.tc.isFailed()))
self.conclude() self.conclude()
if gConfig.auto_start_service : if gConfig.auto_start_service:
svcMgr.stopTaosService() svcMgr.stopTaosService()
# print("TC failed (2) = {}".format(self.tc.isFailed())) # print("TC failed (2) = {}".format(self.tc.isFailed()))
# Linux return code: ref https://shapeshed.com/unix-exit-codes/ # Linux return code: ref https://shapeshed.com/unix-exit-codes/
...@@ -2248,23 +2271,56 @@ def main(): ...@@ -2248,23 +2271,56 @@ def main():
''')) '''))
parser.add_argument('-a', '--auto-start-service', action='store_true', parser.add_argument(
'-a',
'--auto-start-service',
action='store_true',
help='Automatically start/stop the TDengine service (default: false)') help='Automatically start/stop the TDengine service (default: false)')
parser.add_argument('-c', '--connector-type', action='store', default='native', type=str, parser.add_argument(
'-c',
'--connector-type',
action='store',
default='native',
type=str,
help='Connector type to use: native, rest, or mixed (default: 10)') help='Connector type to use: native, rest, or mixed (default: 10)')
parser.add_argument('-d', '--debug', action='store_true', parser.add_argument(
'-d',
'--debug',
action='store_true',
help='Turn on DEBUG mode for more logging (default: false)') help='Turn on DEBUG mode for more logging (default: false)')
parser.add_argument('-e', '--run-tdengine', action='store_true', parser.add_argument(
'-e',
'--run-tdengine',
action='store_true',
help='Run TDengine service in foreground (default: false)') help='Run TDengine service in foreground (default: false)')
parser.add_argument('-l', '--larger-data', action='store_true', parser.add_argument(
'-l',
'--larger-data',
action='store_true',
help='Write larger amount of data during write operations (default: false)') help='Write larger amount of data during write operations (default: false)')
parser.add_argument('-p', '--per-thread-db-connection', action='store_true', parser.add_argument(
'-p',
'--per-thread-db-connection',
action='store_true',
help='Use a single shared db connection (default: false)') help='Use a single shared db connection (default: false)')
parser.add_argument('-r', '--record-ops', action='store_true', parser.add_argument(
'-r',
'--record-ops',
action='store_true',
help='Use a pair of always-fsynced fils to record operations performing + performed, for power-off tests (default: false)') help='Use a pair of always-fsynced fils to record operations performing + performed, for power-off tests (default: false)')
parser.add_argument('-s', '--max-steps', action='store', default=1000, type=int, parser.add_argument(
'-s',
'--max-steps',
action='store',
default=1000,
type=int,
help='Maximum number of steps to run (default: 100)') help='Maximum number of steps to run (default: 100)')
parser.add_argument('-t', '--num-threads', action='store', default=5, type=int, parser.add_argument(
'-t',
'--num-threads',
action='store',
default=5,
type=int,
help='Number of threads to run (default: 10)') help='Number of threads to run (default: 10)')
global gConfig global gConfig
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册