Github user JamesPeach commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/653#discussion_r68602422
  
    --- Diff: iocore/hostdb/HostDB.cc ---
    @@ -300,131 +237,77 @@ HostDBProcessor::cache()
       return &hostDB;
     }
     
    -struct HostDBTestRR : public Continuation {
    -  int fd;
    -  char b[512];
    -  int nb;
    -  int outstanding, success, failure;
    -  int in;
    -
    -  int
    -  mainEvent(int event, Event *e)
    -  {
    -    if (event == EVENT_INTERVAL) {
    -      printf("HostDBTestRR: %d outstanding %d succcess %d failure\n", 
outstanding, success, failure);
    -    }
    -    if (event == EVENT_HOST_DB_LOOKUP) {
    -      --outstanding;
    -      if (e)
    -        ++success;
    -      else
    -        ++failure;
    -    }
    -    if (in)
    -      return EVENT_CONT;
    -    in = 1;
    -    while (outstanding < 40) {
    -      if (!nb)
    -        goto Lreturn;
    -      char *end = (char *)memchr(b, '\n', nb);
    -      if (!end)
    -        read_some();
    -      end = (char *)memchr(b, '\n', nb);
    -      if (!end)
    -        nb = 0;
    -      else {
    -        *end = 0;
    -        outstanding++;
    -        hostDBProcessor.getbyname_re(this, b, 0);
    -        nb -= ((end + 1) - b);
    -        memcpy(b, end + 1, nb);
    -        if (!nb)
    -          read_some();
    -      }
    -    }
    -  Lreturn:
    -    in = 0;
    -    return EVENT_CONT;
    -  }
    -
    -  void
    -  read_some()
    -  {
    -    nb = read(fd, b + nb, 512 - nb);
    -    ink_release_assert(nb >= 0);
    -  }
    -
    -  HostDBTestRR() : Continuation(new_ProxyMutex()), nb(0), outstanding(0), 
success(0), failure(0), in(0)
    -  {
    -    printf("starting HostDBTestRR....\n");
    -    fd = open("hostdb_test.config", O_RDONLY, 0);
    -    ink_release_assert(fd >= 0);
    -    read_some();
    -    SET_HANDLER(&HostDBTestRR::mainEvent);
    -  }
    -
    -  ~HostDBTestRR() { close(fd); }
    -};
    -
    -struct HostDBSyncer : public Continuation {
    +struct HostDBBackgroundTask : public Continuation {
       int frequency;
       ink_hrtime start_time;
     
    -  int sync_event(int event, void *edata);
    +  virtual int sync_event(int event, void *edata) = 0;
       int wait_event(int event, void *edata);
     
    -  HostDBSyncer();
    +  HostDBBackgroundTask(int frequency);
     };
     
    -HostDBSyncer::HostDBSyncer() : Continuation(new_ProxyMutex()), 
frequency(0), start_time(0)
    +HostDBBackgroundTask::HostDBBackgroundTask(int frequency) : 
Continuation(new_ProxyMutex()), frequency(frequency), start_time(0)
     {
    -  SET_HANDLER(&HostDBSyncer::sync_event);
    +  SET_HANDLER(&HostDBBackgroundTask::sync_event);
     }
     
     int
    -HostDBSyncer::sync_event(int, void *)
    +HostDBBackgroundTask::wait_event(int, void *)
     {
    -  SET_HANDLER(&HostDBSyncer::wait_event);
    -  start_time = Thread::get_hrtime();
    -  hostDBProcessor.cache()->sync_partitions(this);
    -  return EVENT_DONE;
    -}
    +  ink_hrtime next_sync = HRTIME_SECONDS(this->frequency) - 
(Thread::get_hrtime() - start_time);
     
    -int
    -HostDBSyncer::wait_event(int, void *)
    -{
    -  ink_hrtime next_sync = HRTIME_SECONDS(hostdb_sync_frequency) - 
(Thread::get_hrtime() - start_time);
    -
    -  SET_HANDLER(&HostDBSyncer::sync_event);
    +  SET_HANDLER(&HostDBBackgroundTask::sync_event);
       if (next_sync > HRTIME_MSECONDS(100))
         eventProcessor.schedule_in(this, next_sync, ET_TASK);
       else
         eventProcessor.schedule_imm(this, ET_TASK);
       return EVENT_DONE;
     }
     
    +struct HostDBSync : public HostDBBackgroundTask {
    +  std::string storage_path;
    +  std::string full_path;
    +  HostDBSync(int frequency, std::string storage_path, std::string 
full_path)
    +    : HostDBBackgroundTask(frequency), storage_path(storage_path), 
full_path(full_path){};
    +  int
    +  sync_event(int, void *)
    +  {
    +    SET_HANDLER(&HostDBSync::wait_event);
    +    start_time = Thread::get_hrtime();
    +
    +    new RefCountCacheSync<RefCountCache<HostDBInfo>>(this, 
hostDBProcessor.cache()->refcountcache, this->frequency,
    +                                                     this->storage_path, 
this->full_path);
    +    return EVENT_DONE;
    +  }
    +};
    +
     int
     HostDBCache::start(int flags)
     {
    -  Store *hostDBStore;
    -  Span *hostDBSpan;
    +  (void)flags; // unused
       char storage_path[PATH_NAME_MAX];
    -  int storage_size = 33554432; // 32MB default
    -
    -  bool reconfigure = ((flags & PROCESSOR_RECONFIGURE) ? true : false);
    -  bool fix         = ((flags & PROCESSOR_FIX) ? true : false);
    +  int hostdb_max_size   = 33554432; // 32MB default
    +  int hostdb_partitions = 64;
     
       storage_path[0] = '\0';
     
       // Read configuration
       // Command line overrides manager configuration.
       //
       REC_ReadConfigInt32(hostdb_enable, "proxy.config.hostdb");
    -  REC_ReadConfigString(hostdb_filename, "proxy.config.hostdb.filename", 
sizeof(hostdb_filename));
    -  REC_ReadConfigInt32(hostdb_size, "proxy.config.hostdb.size");
       REC_ReadConfigInt32(hostdb_srv_enabled, "proxy.config.srv_enabled");
       REC_ReadConfigString(storage_path, "proxy.config.hostdb.storage_path", 
sizeof(storage_path));
    -  REC_ReadConfigInt32(storage_size, "proxy.config.hostdb.storage_size");
    +  REC_ReadConfigString(hostdb_filename, "proxy.config.hostdb.filename", 
sizeof(hostdb_filename));
    +
    +  // Max number of items
    +  REC_ReadConfigInt32(hostdb_max_count, "proxy.config.hostdb.max_count");
    +  // max size allowed to use
    +  REC_ReadConfigInt32(hostdb_max_size, "proxy.config.hostdb.max_size");
    --- End diff --
    
    It's not the -1, it is the ``uint32_t`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to