Exemplo n.º 1
0
    bool ObRange::intersect(const ObRange& r) const
    {
      // suppose range.start_key_ <= range.end_key_
      if (table_id_ != r.table_id_) return false;
      if (empty() || r.empty()) return false;
      if (is_whole_range() || r.is_whole_range()) return true;

      ObString lkey, rkey;
      bool ret = false;
      int8_t include_lborder = 0;
      int8_t include_rborder = 0;
      bool min_value = false;
      int cmp = compare_with_endkey(r);
      if (cmp < 0)
      {
        lkey = end_key_;
        rkey = r.start_key_;
        include_lborder = (border_flag_.inclusive_end());
        include_rborder = (r.border_flag_.inclusive_start());
        min_value = (r.border_flag_.is_min_value());
      }
      else if (cmp > 0)
      {
        lkey = r.end_key_;
        rkey = start_key_;
        include_lborder = (r.border_flag_.inclusive_end());
        include_rborder = (border_flag_.inclusive_start());
        min_value = (border_flag_.is_min_value());
      }
      else
      {
        ret = true;
      }

      if (cmp != 0) 
      {
        if (min_value) ret = true;
        else if (lkey < rkey) ret = false;
        else if (lkey > rkey) ret = true;
        else ret = (include_lborder != 0 && include_rborder != 0);
      }

      return ret;
    }
Exemplo n.º 2
0
int TabletManagerIniter::create_tablet(const ObRange& range,
                                       const ObSSTableId& sst_id, bool serving,
                                       const int64_t version)
{
    int ret = OB_SUCCESS;

    if (range.empty())
    {
        TBSYS_LOG(ERROR, "create_tablet error, input range is empty.");
        ret = OB_INVALID_ARGUMENT;
    }

    if (OB_SUCCESS == ret)
    {
        ObTablet* tablet = NULL;
        // find tablet if exist?
        ObMultiVersionTabletImage &image =  tablet_mgr_.get_serving_tablet_image() ;
        ret = image.acquire_tablet(range, ObMultiVersionTabletImage::SCAN_FORWARD, version, tablet);
        if (OB_SUCCESS == ret)
        {
            TBSYS_LOG(ERROR, "tablet already exists! dump input and exist:");
            range.hex_dump(TBSYS_LOG_LEVEL_ERROR);
            tablet->get_range().hex_dump(TBSYS_LOG_LEVEL_ERROR);
            ret = OB_ERROR;
            tablet = NULL;
            image.release_tablet(tablet);
        }
        else
        {
            ret = image.alloc_tablet_object(range, version, tablet);
            if (OB_SUCCESS == ret)
            {
                ret = tablet->add_sstable_by_id(sst_id);
            }
            if (OB_SUCCESS == ret)
            {
                tablet->set_disk_no(sst_id.sstable_file_id_ & DISK_NO_MASK);
                ret = image.add_tablet(tablet, true, true);
            }
        }
    }

    return ret;
}