本文整理汇总了Python中twitter.common.recordio.ThriftRecordReader类的典型用法代码示例。如果您正苦于以下问题:Python ThriftRecordReader类的具体用法?Python ThriftRecordReader怎么用?Python ThriftRecordReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThriftRecordReader类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _wait_for_control
def _wait_for_control(self):
"""Wait for control of the checkpoint stream: must be run in the child."""
total_wait_time = Amount(0, Time.SECONDS)
with open(self.ckpt_file(), 'r') as fp:
fp.seek(self._ckpt_head)
rr = ThriftRecordReader(fp, RunnerCkpt)
while total_wait_time < self.MAXIMUM_CONTROL_WAIT:
ckpt_tail = os.path.getsize(self.ckpt_file())
if ckpt_tail == self._ckpt_head:
self._platform.clock().sleep(self.CONTROL_WAIT_CHECK_INTERVAL.as_(Time.SECONDS))
total_wait_time += self.CONTROL_WAIT_CHECK_INTERVAL
continue
checkpoint = rr.try_read()
if checkpoint:
if not checkpoint.process_status:
raise self.CheckpointError('No process status in checkpoint!')
if (checkpoint.process_status.process != self.name() or
checkpoint.process_status.state != ProcessState.FORKED or
checkpoint.process_status.fork_time != self._fork_time or
checkpoint.process_status.coordinator_pid != self._pid):
self._log('Losing control of the checkpoint stream:')
self._log(' fork_time [%s] vs self._fork_time [%s]' % (
checkpoint.process_status.fork_time, self._fork_time))
self._log(' coordinator_pid [%s] vs self._pid [%s]' % (
checkpoint.process_status.coordinator_pid, self._pid))
raise self.CheckpointError('Lost control of the checkpoint stream!')
self._log('Taking control of the checkpoint stream at record: %s' %
checkpoint.process_status)
self._seq = checkpoint.process_status.seq + 1
return True
raise self.CheckpointError('Timed out waiting for checkpoint stream!')
开发者ID:ssalevan,项目名称:aurora,代码行数:32,代码来源:process.py
示例2: _fast_forward_stream
def _fast_forward_stream(self, process_name):
log.debug('Fast forwarding %s stream to seq=%s' % (process_name,
self._watermarks[process_name]))
assert self._processes.get(process_name) is not None
fp = self._processes[process_name]
rr = ThriftRecordReader(fp, RunnerCkpt)
current_watermark = -1
records = 0
while current_watermark < self._watermarks[process_name]:
last_pos = fp.tell()
record = rr.try_read()
if record is None:
break
new_watermark = record.process_status.seq
if new_watermark > self._watermarks[process_name]:
log.debug('Over-seeked %s [watermark = %s, high watermark = %s], rewinding.' % (
process_name, new_watermark, self._watermarks[process_name]))
fp.seek(last_pos)
break
current_watermark = new_watermark
records += 1
if current_watermark < self._watermarks[process_name]:
log.warning('Only able to fast forward to %[email protected]=%s, high watermark is %s' % (
process_name, current_watermark, self._watermarks[process_name]))
if records:
log.debug('Fast forwarded %s %s record(s) to seq=%s.' % (process_name, records,
current_watermark))
开发者ID:sumanau7,项目名称:incubator-aurora,代码行数:29,代码来源:muxer.py
示例3: select
def select(self):
"""
Read and multiplex checkpoint records from all the forked off process coordinators.
Checkpoint records can come from one of two places:
in-process: checkpoint records synthesized for FORKED and LOST events
out-of-process: checkpoint records from from file descriptors of forked coordinators
Returns a list of RunnerCkpt objects that were successfully read, or an empty
list if none were read.
"""
self._bind_processes()
updates = []
for handle in filter(None, self._processes.values()):
try:
fstat = os.fstat(handle.fileno())
except OSError as e:
log.error('Unable to fstat %s!' % handle.name)
continue
if handle.tell() > fstat.st_size:
log.error('Truncated checkpoint record detected on %s!' % handle.name)
elif handle.tell() < fstat.st_size:
rr = ThriftRecordReader(handle, RunnerCkpt)
while True:
process_update = rr.try_read()
if process_update:
updates.append(process_update)
else:
break
if len(updates) > 0:
log.debug('select() returning %s updates:' % len(updates))
for update in updates:
log.debug(' = %s' % update)
return updates
开发者ID:sumanau7,项目名称:incubator-aurora,代码行数:34,代码来源:muxer.py
示例4: _apply_states
def _apply_states(self):
"""
os.stat() the corresponding checkpoint stream of this task and determine if there are new ckpt
records. Attempt to read those records and update the high watermark for that stream.
Returns True if new states were applied, False otherwise.
"""
ckpt_offset = None
try:
ckpt_offset = os.stat(self._runner_ckpt).st_size
updated = False
if self._ckpt_head < ckpt_offset:
with open(self._runner_ckpt, "r") as fp:
fp.seek(self._ckpt_head)
rr = ThriftRecordReader(fp, RunnerCkpt)
while True:
runner_update = rr.try_read()
if not runner_update:
break
try:
self._dispatcher.dispatch(self._runnerstate, runner_update)
except CheckpointDispatcher.InvalidSequenceNumber as e:
log.error("Checkpoint stream is corrupt: %s" % e)
break
new_ckpt_head = fp.tell()
updated = self._ckpt_head != new_ckpt_head
self._ckpt_head = new_ckpt_head
return updated
except OSError as e:
if e.errno == errno.ENOENT:
# The log doesn't yet exist, will retry later.
log.warning("Could not read from checkpoint %s" % self._runner_ckpt)
return False
else:
raise
开发者ID:rowoot,项目名称:aurora,代码行数:35,代码来源:monitor.py
示例5: wait_for_rc
def wait_for_rc(checkpoint, timeout=5.0):
start = time.time()
trr = ThriftRecordReader(open(checkpoint), RunnerCkpt)
while time.time() < start + timeout:
record = trr.read()
if record and record.process_status and record.process_status.return_code is not None:
return record.process_status.return_code
else:
time.sleep(0.1)
开发者ID:MustafaOrkunAcar,项目名称:incubator-aurora,代码行数:9,代码来源:test_process.py
示例6: test_thrift_garbage
def test_thrift_garbage():
with EphemeralFile('w') as fp:
fn = fp.name
fp.write(struct.pack('>L', 2))
fp.write('ab')
fp.close()
with open(fn) as fpr:
rr = ThriftRecordReader(fpr, StringType)
with pytest.raises(RecordIO.PrematureEndOfStream):
rr.read()
开发者ID:DikangGu,项目名称:commons,代码行数:12,代码来源:thrift_recordio_test.py
示例7: _replay_runner_ckpt
def _replay_runner_ckpt(self):
"""
Replay the checkpoint stream associated with this task.
"""
ckpt_file = self._pathspec.getpath('runner_checkpoint')
if os.path.exists(ckpt_file):
fp = open(ckpt_file, "r")
ckpt_recover = ThriftRecordReader(fp, RunnerCkpt)
for record in ckpt_recover:
log.debug('Replaying runner checkpoint record: %s' % record)
self._dispatcher.dispatch(self._state, record, recovery=True)
ckpt_recover.close()
开发者ID:sumanau7,项目名称:incubator-aurora,代码行数:12,代码来源:runner.py
示例8: test_basic_thriftrecordwriter_write
def test_basic_thriftrecordwriter_write():
test_string = StringType("hello world")
with EphemeralFile('w') as fp:
fn = fp.name
rw = ThriftRecordWriter(fp)
rw.write(test_string)
rw.close()
with open(fn) as fpr:
rr = ThriftRecordReader(fpr, StringType)
assert rr.read() == test_string
开发者ID:DikangGu,项目名称:commons,代码行数:13,代码来源:thrift_recordio_test.py
示例9: test_thrift_recordwriter_type_mismatch
def test_thrift_recordwriter_type_mismatch():
test_string = StringType("hello world")
with EphemeralFile('w') as fp:
fn = fp.name
rw = ThriftRecordWriter(fp)
rw.write(test_string)
rw.close()
with open(fn) as fpr:
rr = ThriftRecordReader(fpr, IntType)
# This is a peculiar behavior of Thrift in that it just returns
# ThriftType() with no serialization applied
assert rr.read() == IntType()
开发者ID:DikangGu,项目名称:commons,代码行数:14,代码来源:thrift_recordio_test.py
示例10: test_paranoid_thrift_append_framing
def test_paranoid_thrift_append_framing():
test_string_1 = StringType("hello world")
test_string_2 = StringType("ahoy ahoy, bonjour")
with EphemeralFile('w') as fp:
fn = fp.name
ThriftRecordWriter.append(fn, test_string_1)
ThriftRecordWriter.append(fn, test_string_2)
with open(fn) as fpr:
rr = ThriftRecordReader(fpr, StringType)
assert rr.read() == test_string_1
assert rr.read() == test_string_2
开发者ID:DikangGu,项目名称:commons,代码行数:14,代码来源:thrift_recordio_test.py
示例11: test_thriftrecordwriter_framing
def test_thriftrecordwriter_framing():
test_string_1 = StringType("hello world")
test_string_2 = StringType("ahoy ahoy, bonjour")
with EphemeralFile('w') as fp:
fn = fp.name
rw = ThriftRecordWriter(fp)
rw.write(test_string_1)
rw.close()
with open(fn, 'a') as fpa:
rw = ThriftRecordWriter(fpa)
rw.write(test_string_2)
with open(fn) as fpr:
rr = ThriftRecordReader(fpr, StringType)
assert rr.read() == test_string_1
assert rr.read() == test_string_2
开发者ID:DikangGu,项目名称:commons,代码行数:19,代码来源:thrift_recordio_test.py
示例12: has_data
def has_data(self, process):
"""
Return true if we think that there are updates available from the supplied process.
"""
self._bind_processes()
# TODO(wickman) Should this raise ProcessNotFound?
if process not in self._processes:
return False
fp = self._processes[process]
rr = ThriftRecordReader(fp, RunnerCkpt)
old_pos = fp.tell()
try:
expected_new_pos = os.fstat(fp.fileno()).st_size
except OSError as e:
log.debug('ProcessMuxer could not fstat for process %s' % process)
return False
update = rr.try_read()
if update:
fp.seek(old_pos)
return True
return False
开发者ID:sumanau7,项目名称:incubator-aurora,代码行数:21,代码来源:muxer.py
注:本文中的twitter.common.recordio.ThriftRecordReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论