class_docstr: Instance storage stores the states of instances in the storage. It also
  allows users to subscribe to instance status changes to trigger reconciliation
  with cloud provider.
docstr: Upsert an instance in the storage.
  If the expected_instance_version is specified, the update will fail
  if the current instance version does not match the expected version.
  Similarly, if the expected_storage_version is
  specified, the update will fail if the current storage version does not
  match the expected version.
  
  Note the version of the upserted instances will be set to the current
  storage version.
  
  Args:
      instance: The instance to be updated.
      expected_instance_version: The expected instance version.
      expected_storage_version: The expected storage version.
  
  Returns:
      StoreStatus: A tuple of (success, storage_version).
docstr_tok: ["Upsert","an","instance","in","the","storage",".","If","the","expected_instance_version","is","specified",",","the","update","will","fail","if","the","current","instance","version","does","not","match","the","expected","version",".","Similarly",",","if","the","expected_storage_version","is","specified",",","the","update","will","fail","if","the","current","storage","version","does","not","match","the","expected","version",".","Note","the","version","of","the","upserted","instances","will","be","set","to","the","current","storage","version",".","Args",":","instance",":","The","instance","to","be","updated",".","expected_instance_version",":","The","expected","instance","version",".","expected_storage_version",":","The","expected","storage","version",".","Returns",":","StoreStatus",":","A","tuple","of","(","success",",","storage_version",")","."]
code: def upsert_instance(
      self,
      instance: Instance,
      expected_instance_version: Optional[int] = None,
      expected_storage_verison: Optional[int] = None,
  ) -> StoreStatus:
      """Upsert an instance in the storage.
      If the expected_instance_version is specified, the update will fail
      if the current instance version does not match the expected version.
      Similarly, if the expected_storage_version is
      specified, the update will fail if the current storage version does not
      match the expected version.
  
      Note the version of the upserted instances will be set to the current
      storage version.
  
      Args:
          instance: The instance to be updated.
          expected_instance_version: The expected instance version.
          expected_storage_version: The expected storage version.
  
      Returns:
          StoreStatus: A tuple of (success, storage_version).
      """
      instance = copy.deepcopy(instance)
      # the instance version is set to 0, it will be
      # populated by the storage entry's verion on read
      instance.version = 0
      result, version = self._storage.update(
          self._table_name,
          key=instance.instance_id,
          value=instance.SerializeToString(),
          expected_entry_version=expected_instance_version,
          expected_storage_version=expected_storage_verison,
          insert_only=False,
      )
  
      if result:
          for subscriber in self._status_change_subscribers:
              subscriber.notify(
                  [
                      InstanceUpdateEvent(
                          instance_id=instance.instance_id,
                          new_instance_status=instance.status,
                      )
                  ],
              )
  
      return StoreStatus(result, version)
  
file_path: ray/python/ray/autoscaler/v2/instance_manager/instance_storage.py
imports: import copy
  import logging
  from abc import ABCMeta, abstractmethod
  from typing import Dict, List, Optional, Set, Tuple
  from ray.autoscaler.v2.instance_manager.storage import Storage, StoreStatus
  from ray.core.generated.instance_manager_pb2 import Instance, InstanceUpdateEvent
label_desc: Use image node_id 4 for calling the InstanceStorage obj's underlying member method code with example usage: obj.upsert_instance(instance, expected_instance_version, expected_storage_verison) and returns: StoreStatus