<commit_before>#include "dhash_store.h"
#include "dhblock.h"

#include <location.h>
#include <locationtable.h>
#include <misc_utils.h>
#include <modlogger.h>

#define warning modlogger ("dhash_store", modlogger::WARNING)
#define info  modlogger ("dhash_store", modlogger::INFO)
#define trace modlogger ("dhash_store", modlogger::TRACE)

// ---------------------------------------------------------------------------
// DHASH_STORE
//     - store a give block of data on a give nodeID.
//     - the address of the nodeID must already by in the location cache.
//     - XXX don't really handle RACE conditions..

#define STORE_TIMEOUT 60
    
void 
dhash_store::start ()
{
  error = false;
  status = DHASH_OK;
  npending = 0;
  int blockno = 0;

  unsigned int mtu;
  if (clntnode->my_location ()->id () == dest->id ())
    mtu = data.len ();
  else
    mtu = dhblock::dhash_mtu ();
  
  dcb = delaycb
    (STORE_TIMEOUT, wrap (this, &dhash_store::timed_out, mkref(this)));
  
  size_t nstored = 0;
  while (nstored < data.len ()) {
    size_t chunklen = MIN (mtu, data.len () - nstored);
    char  *chunkdat = (char *)(data.cstr () + nstored);
    size_t chunkoff = nstored;
    npending++;
    store (dest, bid, chunkdat, chunklen, chunkoff, 
	   data.len (), blockno, ctype, store_type);
    nstored += chunklen;
    blockno++;
  }
}<commit_msg>don't crash when storing a very large (100 KB) block if the inserter will be one of the replicas.<commit_after>#include "dhash_store.h"
#include "dhblock.h"

#include <location.h>
#include <locationtable.h>
#include <misc_utils.h>
#include <modlogger.h>

#define warning modlogger ("dhash_store", modlogger::WARNING)
#define info  modlogger ("dhash_store", modlogger::INFO)
#define trace modlogger ("dhash_store", modlogger::TRACE)

// ---------------------------------------------------------------------------
// DHASH_STORE
//     - store a give block of data on a give nodeID.
//     - the address of the nodeID must already by in the location cache.
//     - XXX don't really handle RACE conditions..

#define STORE_TIMEOUT 60
    
void 
dhash_store::start ()
{
  error = false;
  status = DHASH_OK;
  npending = 0;
  int blockno = 0;

  unsigned int mtu;
  mtu = dhblock::dhash_mtu ();
  
  dcb = delaycb
    (STORE_TIMEOUT, wrap (this, &dhash_store::timed_out, mkref(this)));
  
  size_t nstored = 0;
  while (nstored < data.len ()) {
    size_t chunklen = MIN (mtu, data.len () - nstored);
    char  *chunkdat = (char *)(data.cstr () + nstored);
    size_t chunkoff = nstored;
    npending++;
    store (dest, bid, chunkdat, chunklen, chunkoff, 
	   data.len (), blockno, ctype, store_type);
    nstored += chunklen;
    blockno++;
  }
}
{'fraction_non_alphanumeric': 0.18462109955423478, 'fraction_numerical': 0.0048291233283803865, 'mean_word_length': 2.7196132596685083, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5282192', 'n_tokens_mistral': 948, 'n_tokens_neox': 914, 'n_words': 257}