def _GetUnsortedNotifications(self, queue_shard,
                                notifications_by_session_id=None):
    if notifications_by_session_id is None:
      notifications_by_session_id = {}
    end_time = self.frozen_timestamp or rdfvalue.RDFDatetime().Now()
    for predicate, serialized_notification, ts in self.data_store.ResolvePrefix(
        queue_shard, self.NOTIFY_PREDICATE_PREFIX,
        timestamp=(0, end_time),
        token=self.token, limit=10000):

      # Parse the notification.
      try:
        notification = rdf_flows.GrrNotification(serialized_notification)
      except Exception:  # pylint: disable=broad-except
        logging.exception("Can't unserialize notification, deleting it: "
                          "predicate=%s, ts=%d", predicate, ts)
        self.data_store.DeleteAttributes(
            queue_shard, [predicate], token=self.token,
            # Make the time range narrow, but be sure to include the needed
            # notification.
            start=ts, end=ts, sync=True)
        continue

      # Strip the prefix from the predicate to get the session_id.
      session_id = predicate[len(self.NOTIFY_PREDICATE_PREFIX):]
      notification.session_id = session_id
      notification.timestamp = ts

      existing = notifications_by_session_id.get(notification.session_id)
      if existing:
        # If we have a notification for this session_id already, we only store
        # the one that was scheduled last.
        if notification.first_queued > existing.first_queued:
          notifications_by_session_id[notification.session_id] = notification
        elif notification.first_queued == existing.first_queued and (
            notification.last_status > existing.last_status):
          # Multiple notifications with the same timestamp should not happen.
          # We can still do the correct thing and use the latest one.
          logging.warn(
              "Notifications with equal first_queued fields detected: %s %s",
              notification, existing)
          notifications_by_session_id[notification.session_id] = notification
      else:
        notifications_by_session_id[notification.session_id] = notification

    return notifications_by_session_id
Returns all the available notifications for a queue_shard.
dataset/ETHPy150Open google/grr/grr/lib/queue_manager.py/QueueManager._GetUnsortedNotifications