code: func (m *UnpartitionedMemoryIdx) AddOrUpdate(mkey schema.MKey, data *schema.MetricData, partition int32) (idx.Archive, int32, bool) {
  	pre := time.Now()
  
  	// Optimistically read lock
  	m.RLock()
  
  	existing, ok := m.defById[mkey]
  	if ok {
  		if log.IsLevelEnabled(log.DebugLevel) {
  			log.Debugf("memory-idx: metricDef with id %s already in index.", mkey)
  		}
  		bumpLastUpdate(&existing.LastUpdate, data.Time)
  		oldPart := atomic.SwapInt32(&existing.Partition, partition)
  		statUpdate.Inc()
  		statUpdateDuration.Value(time.Since(pre))
  		m.RUnlock()
  		return *existing, oldPart, ok
  	}
  
  	m.RUnlock()
  	m.Lock()
  	defer m.Unlock()
  
  	def := schema.MetricDefinitionFromMetricData(data)
  	def.Partition = partition
  	archive := m.add(def)
  	statMetricsActive.Inc()
  	statAddDuration.Value(time.Since(pre))
  
  	if TagSupport {
  		m.indexTags(def)
  	}
  
  	return archive, 0, false
  }
docs: // AddOrUpdate returns the corresponding Archive for the MetricData.
  // if it is existing -> updates lastUpdate based on .Time, and partition
  // if was new        -> adds new MetricDefinition to index