@utils.Synchronized
  def _WriteAttributes(self, sync=True):
    # If the object is not opened for writing we do not need to flush it to the
    # data_store.
    if "w" not in self.mode:
      return

    if self.urn is None:
      raise RuntimeError("Storing of anonymous AFF4 objects not supported.")

    to_set = {}
    for attribute_name, value_array in self.new_attributes.iteritems():
      to_set_list = to_set.setdefault(attribute_name, [])
      for value in value_array:
        to_set_list.append((value.SerializeToDataStore(), value.age))

    if self._dirty:
      # We determine this object has a new version only if any of the versioned
      # attributes have changed. Non-versioned attributes do not represent a new
      # object version. The type of an object is versioned and represents a
      # version point in the life of the object.
      if self._new_version:
        to_set[self.Schema.TYPE] = [
            (rdfvalue.RDFString(self.__class__.__name__).SerializeToDataStore(),
             rdfvalue.RDFDatetime().Now())]

      # We only update indexes if the schema does not forbid it and we are not
      # sure that the object already exists.
      add_child_index = self.Schema.ADD_CHILD_INDEX
      if self.object_exists:
        add_child_index = False

      # Write the attributes to the Factory cache.
      FACTORY.SetAttributes(self.urn, to_set, self._to_delete,
                            add_child_index=add_child_index,
                            mutation_pool=self.mutation_pool,
                            sync=sync, token=self.token)
Write the dirty attributes to the data store.
dataset/ETHPy150Open google/grr/grr/lib/aff4.py/AFF4Object._WriteAttributes