Exemplo n.º 1
0
  def delete(self, start_id, end_id):
    shards = list(self.get_overlapping_shards(uuid_to_kronos_time(start_id),
                                              uuid_to_kronos_time(end_id)))

    def delete_from_shard(shard):
      batch_stmt = BatchStatement(batch_type=BatchType.UNLOGGED,
                                  consistency_level=ConsistencyLevel.QUORUM)
      num_deleted = 0
      shard = StreamShard(self.namespace, self.stream,
                          shard['start_time'], shard['width'],
                          shard['shard'], False,
                          MAX_LIMIT, read_size=self.read_size)
      for _id in shard.ids_iterator(start_id, end_id):
        if _id == start_id:
          continue
        num_deleted += 1
        batch_stmt.add(BoundStatement(self.namespace.DELETE_STMT,
                                      routing_key=shard.key,
                                      consistency_level=ConsistencyLevel.QUORUM)
                       .bind((shard.key, _id)))
      self.session.execute(batch_stmt)
      return num_deleted

    for i, shard in enumerate(shards):
      shards[i] = execute_greenlet_async(delete_from_shard, shard)
    wait(shards)

    errors = []
    num_deleted = 0
    for shard in shards:
      try:
        num_deleted += shard.get()
      except Exception, e:
        errors.append(repr(e))
Exemplo n.º 2
0
      log.exception('put_events: stream validation failed for `%s`', stream)
      errors.append(repr(e))
      continue

    for event in events:
      try:
        events_to_insert[stream].append(validate_event_and_assign_id(event))
      except Exception, e:
        log.exception('put_events: event validation failed for `%s`', event)
        errors.append(repr(e))

  results = {}
  for stream, events in events_to_insert.iteritems():
    backends = router.backends_to_mutate(namespace, stream)
    for backend, configuration in backends.iteritems():
      results[(stream, backend.name)] = execute_greenlet_async(
        backend.insert, namespace, stream, events, configuration)
  wait(results.values())

  # Did any insertion fail?
  success = True
  response = defaultdict(dict)
  for (stream, backend), result in results.iteritems():
    try:
      result.get()
      response[stream][backend] = {
        'num_inserted': len(events_to_insert[stream])
      }
    except Exception, e:
      log.exception('put_events: insertion to backend `%s` failed.', backend)
      success = False
      response[stream][backend] = {'num_inserted': -1,
Exemplo n.º 3
0
            continue

        for event in events:
            try:
                events_to_insert[stream].append(
                    validate_event_and_assign_id(event))
            except Exception, e:
                log.exception('put_events: event validation failed for `%s`',
                              event)
                errors.append(repr(e))

    results = {}
    for stream, events in events_to_insert.iteritems():
        backends = router.backends_to_mutate(namespace, stream)
        for backend, configuration in backends.iteritems():
            results[(stream, backend.name)] = execute_greenlet_async(
                backend.insert, namespace, stream, events, configuration)
    wait(results.values())

    # Did any insertion fail?
    success = True
    response = defaultdict(dict)
    for (stream, backend), result in results.iteritems():
        try:
            result.get()
            response[stream][backend] = {
                'num_inserted': len(events_to_insert[stream])
            }
        except Exception, e:
            log.exception('put_events: insertion to backend `%s` failed.',
                          backend)
            success = False