예제 #1
0
 bool bucket_waiting_queue::send(int64_t now)
 {
    bool empty = true;
    tbsys::CThreadGuard guard(&mutex);
    map<uint64_t, packets_queue_type>::iterator it = packets_queue.begin();
    for (it = packets_queue.begin(); it != packets_queue.end(); ++it) {
       packets_queue_type queue = it->second;
       if (queue.empty()) continue;
       empty = false;
       int64_t& last_time = last_send_time[it->first];
       if (now - last_time < MISECONDS_BEFOR_SEND_RETRY) {
          continue;
       }
       request_duplicate* packet = new request_duplicate(*queue.front());
       log_debug("will send packet pid = %d", packet->packet_id);
       PROFILER_START("do duplicate");
       PROFILER_BEGIN("send duplicate packet");
       if (psm->conn_mgr->sendPacket(it->first, packet, NULL, NULL, true) == false) {
          log_debug("send duplicate packet failed: %s", tbsys::CNetUtil::addrToString(it->first).c_str());
          delete packet;
       } else {
          log_debug("duplicate packet sent: %s", tbsys::CNetUtil::addrToString(it->first).c_str());
          last_time = now;
       }
       PROFILER_END();
       PROFILER_DUMP();
       PROFILER_STOP();
    }
    return !empty;
 }
예제 #2
0
   bool tair_server::handlePacketQueue(tbnet::Packet *apacket, void *args)
   {
      base_packet *packet = (base_packet*)apacket;
      int pcode = packet->getPCode();

      bool send_return = true;
      int ret = TAIR_RETURN_SUCCESS;
      const char *msg = "";
      char buf[100];
      sprintf(buf, "pcode is %d, ip is %u", pcode, (uint32_t)(packet->get_connection()->getServerId() & 0xffffffff));
      PROFILER_START("process request");
      PROFILER_BEGIN(buf);
      switch (pcode) {
		  case TAIR_REQ_TTL_PACKET:
		  {
		      request_ttl *npacket = (request_ttl *)packet;
			  ret = req_processor->process(npacket, send_return);
			  break;
		  }
		  case TAIR_REQ_TYPE_PACKET:
		  {
			  request_type *npacket = (request_type *)packet;
			  ret = req_processor->process(npacket, send_return);
			  break;
		  }
		  case TAIR_REQ_EXISTS_PACKET:
		  {
			  request_exists *npacket = (request_exists *)packet;
			  ret = req_processor->process(npacket, send_return);
			  break;
		  }
		  case TAIR_REQ_PUT_PACKET:
		  {
			  request_put *npacket = (request_put *)packet;
			  ret = req_processor->process (npacket, send_return);
			  break;
		  }
          case TAIR_REQ_PUTNX_PACKET:
          {
              request_putnx *npacket = (request_putnx *)packet;
              ret = req_processor->process (npacket, send_return);
              break;
          }
		  case TAIR_REQ_GET_PACKET:
		  {
			  request_get *npacket = (request_get *) packet;
			  ret = req_processor->process (npacket, send_return);
			  send_return = false;
			  break;
		  }
		  case TAIR_REQ_GETSET_PACKET:
		  {
			  request_getset *npacket = (request_getset *)packet;
			  ret = req_processor->process(npacket, send_return);
			  break;
		  }
		  case TAIR_REQ_REMOVE_PACKET:
		  {
			  request_remove *npacket = (request_remove *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end remove,prepare to send return packet");
			  break;
		  }
		  case TAIR_REQ_LINDEX_PACKET:
		  {
			  request_lindex *npacket = (request_lindex *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end lindex, prepare to send return packet");
			  break;
		  }
		  case TAIR_REQ_LPOP_PACKET:
		  case TAIR_REQ_RPOP_PACKET:
		  {
			  request_lrpop *npacket = (request_lrpop *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end lrpop, prepare to send return packet");
			  break;
		  }
		  case TAIR_REQ_LPUSH_PACKET:
		  case TAIR_REQ_RPUSH_PACKET:
		  case TAIR_REQ_LPUSHX_PACKET:
		  case TAIR_REQ_RPUSHX_PACKET:
		  {
			  request_lrpush *npacket = (request_lrpush *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end lrpush, prepare to send return packet");
			  break;
		  }
		  case TAIR_REQ_LPUSH_LIMIT_PACKET:
		  case TAIR_REQ_RPUSH_LIMIT_PACKET:
		  case TAIR_REQ_LPUSHX_LIMIT_PACKET:
		  case TAIR_REQ_RPUSHX_LIMIT_PACKET:
		  {
			  request_lrpush_limit *npacket = (request_lrpush_limit *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end lrpush limit, prepare to send return packet");
			  break;
		  }
          case TAIR_REQ_HEXISTS_PACKET:
          {
              request_hexists *npacket = (request_hexists *) packet;
              ret = req_processor->process (npacket, send_return);
			  log_debug ("end hexists, prepare to send return packet");

			  break;
          }
		  case TAIR_REQ_HGETALL_PACKET:
		  {
			  request_hgetall *npacket = (request_hgetall *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hgetall, prepare to send return packet");

			  break;
		  }
          case TAIR_REQ_HKEYS_PACKET:
          {
              request_hkeys *npacket = (request_hkeys *) packet;
              ret = req_processor->process (npacket, send_return);
              log_debug ("end hkeys, prepare to send return packet");

              break;
          }
		  case TAIR_REQ_HINCRBY_PACKET:
		  {
			  request_hincrby *npacket = (request_hincrby *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hincrby, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_HMSET_PACKET:
		  {
			  request_hmset *npacket = (request_hmset *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hmset, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_HSET_PACKET:
		  {
			  request_hset *npacket = (request_hset *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hset, prepare to send return packet");
			  break;
		  }
	  	  case TAIR_REQ_HSETNX_PACKET:
		  {
			  request_hsetnx *npacket = (request_hsetnx *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hsetnx, prepare to send return packet");
			  break;
		  }
	      case TAIR_REQ_HGET_PACKET:
		  {
			  request_hget *npacket = (request_hget *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hget, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_HMGET_PACKET:
		  {
			  request_hmget *npacket = (request_hmget *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hmget, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_HVALS_PACKET:
		  {
			  request_hvals *npacket = (request_hvals *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hvals, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_HDEL_PACKET:
		  {
			  request_hdel *npacket = (request_hdel *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end hdel, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_HLEN_PACKET:
		  {
			  request_hlen *npacket = (request_hlen *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end llen, prepare to sen return packet");

			  break;
		  }
		  case TAIR_REQ_LTRIM_PACKET:
		  {
			  request_ltrim *npacket = (request_ltrim *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end ltrim, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_LREM_PACKET:
		  {
			  request_lrem *npacket = (request_lrem *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end lrem, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_LLEN_PACKET:
		  {
			  request_llen *npacket = (request_llen *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end llen, prepare to sen return packet");

			  break;
		  }
		  case TAIR_REQ_LRANGE_PACKET:
		  {
			  request_lrange *npacket = (request_lrange *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end lrange, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_SCARD_PACKET:
		  {
			  request_scard *npacket = (request_scard *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end scard, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_SMEMBERS_PACKET:
		  {
			  request_smembers *npacket = (request_smembers *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end smembers, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_SADD_PACKET:
		  {
			  request_sadd *npacket = (request_sadd *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end sadd, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_SREM_PACKET:
		  {
			  request_srem *npacket = (request_srem *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end srem, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_SPOP_PACKET:
		  {
			  request_spop *npacket = (request_spop *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end lrpush, prepare to send return packet");

			  break;
		  }
          case TAIR_REQ_SADDMULTI_PACKET:
          {
              request_sadd_multi *npacket = (request_sadd_multi *) packet;
              ret = req_processor->process (npacket, send_return);
              log_debug ("end request sadd multi, prepare to send return packet");

              break;
          }
          case TAIR_REQ_SREMMULTI_PACKET:
          {
              request_srem_multi *npacket = (request_srem_multi *) packet;
              ret = req_processor->process (npacket, send_return);
              log_debug ("end request srem multi, prepare to send return packet");

              break;
          }
          case TAIR_REQ_SMEMBERSMULTI_PACKET:
          {
              request_smembers_multi *npacket = (request_smembers_multi *) packet;
              ret = req_processor->process (npacket, send_return);
              log_debug ("end request smembers multi, prepare to send retrun packet");

              break;
          }
		  case TAIR_REQ_ZSCORE_PACKET:
		  {
			  request_zscore *npacket = (request_zscore *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zscore, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_ZRANGE_PACKET:
		  {
			  request_zrange *npacket = (request_zrange *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zrange, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_ZREVRANGE_PACKET:
		  {
			  request_zrevrange *npacket = (request_zrevrange *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zrevrange, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_ZRANGEBYSCORE_PACKET:
		  {
			  request_zrangebyscore *npacket = (request_zrangebyscore *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zrangebyscore, prepare to send return packet");

			  break;
		  }
          case TAIR_REQ_GENERIC_ZRANGEBYSCORE_PACKET:
          {
              request_generic_zrangebyscore *npacket = (request_generic_zrangebyscore *)packet;
              ret = req_processor->process (npacket, send_return);
			  log_debug ("end generic zrangebyscore, prepare to send return packet, send_return=%d",send_return);

			  break;
          }
		  case TAIR_REQ_ZADD_PACKET:
		  {
			  request_zadd *npacket = (request_zadd *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zadd, prepare to send return packet, send_return=%d", send_return);

			  break;
		  }
		  case TAIR_REQ_ZRANK_PACKET:
		  {
			  request_zrank *npacket = (request_zrank *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zrank, prepare to send return packet");
			  break;
		  }
		  case TAIR_REQ_ZREVRANK_PACKET:
		  {
			  request_zrevrank *npacket = (request_zrevrank *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zrevrank, prepare to send return packet, send_return=%d",send_return);
			  break;
		  }
		  case TAIR_REQ_ZCOUNT_PACKET:
		  {
			  request_zcount *npacket = (request_zcount *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zcount, prepare to send return packet");
			  break;
		  }
		  case TAIR_REQ_ZINCRBY_PACKET:
		  {
			  request_zincrby *npacket = (request_zincrby *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zincrby, prepare to send return packet");
			  break;
		  }
		  case TAIR_REQ_ZCARD_PACKET:
		  {
			  request_zcard *npacket = (request_zcard *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zcard, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_ZREM_PACKET:
		  {
			  request_zrem *npacket = (request_zrem *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zrem, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_ZREMRANGEBYRANK_PACKET:
		  {
			  request_zremrangebyrank *npacket = (request_zremrangebyrank *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end zremrangebyrank, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_ZREMRANGEBYSCORE_PACKET:
		  {
			  request_zremrangebyscore *npacket = (request_zremrangebyscore *) packet;
			  ret = req_processor->process (npacket, send_return);
		      log_debug ("end zremrangebyscore, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_EXPIRE_PACKET:
		  {
			  request_expire *npacket = (request_expire *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end expire, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_EXPIREAT_PACKET:
		  {
			  request_expireat *npacket = (request_expireat *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end expireat, prepare to send return packet");

			  break;
		  }
		  case TAIR_REQ_PERSIST_PACKET:
		  {
			  request_persist *npacket = (request_persist *) packet;
			  ret = req_processor->process (npacket, send_return);
			  log_debug ("end persist, prepare to send return packet");

			  break;
		  }
          case TAIR_REQ_INFO_PACKET:
          {
              request_info *npacket = (request_info *) packet;
              ret = req_processor->process (npacket, send_return);
              log_debug ("end info, prepare to send return packet");

              break;
          }
          case TAIR_REQ_LAZY_REMOVE_AREA_PACKET:
          {
              request_lazy_remove_area *npacket = (request_lazy_remove_area *)packet;
              ret = req_processor->process (npacket, send_return);
			  log_debug ("end lazy remove area, prepare to send return packet");

			  break;
          }
          case TAIR_REQ_DUMP_AREA_PACKET:
          {
              request_dump_area *npacket = (request_dump_area *)packet;
              ret = req_processor->process (npacket, send_return);
			  log_debug ("end dump area, prepare to send return packet");

			  break;
          }
          case TAIR_REQ_LOAD_AREA_PACKET:
          {
              request_load_area *npacket = (request_load_area *)packet;
              ret = req_processor->process (npacket, send_return);
			  log_debug ("end dump area, prepare to send return packet");

			  break;
          }
          case TAIR_REQ_ADD_FILTER_PACKET:
          {
              request_addfilter *npacket = (request_addfilter *)packet;
              ret = req_processor->process (npacket, send_return);
              log_debug ("end add filter area, prepare to send return packet");

              break;
          }
          case TAIR_REQ_REMOVE_FILTER_PACKET:
          {
              request_removefilter *npacket = (request_removefilter *)packet;
              ret = req_processor->process (npacket, send_return);
              log_debug ("end add filter area, prepare to send return packet");

              break;
          }
		 case TAIR_REQ_REMOVE_AREA_PACKET:
         {
            request_remove_area *npacket = (request_remove_area*)packet;
            if (npacket->get_direction() == DIRECTION_RECEIVE) {
               async_task_queue_thread.push(new request_remove_area(*npacket));
            } else {
               if (tair_mgr->clear(npacket->area) == false) {
                  ret = EXIT_FAILURE;
               }
            }
            break;
         }
         case TAIR_REQ_PING_PACKET:
         {
            ret = ((request_ping*)packet)->value;
            break;
         }
         case TAIR_REQ_DUMP_PACKET:
         {
            request_dump *npacket = (request_dump*)packet;
            if (npacket->get_direction() == DIRECTION_RECEIVE) {
               async_task_queue_thread.push(new request_dump(*npacket));
            } else {
               tair_mgr->do_dump(npacket->info_set);
            }
            break;
         }
         case TAIR_REQ_DUMP_BUCKET_PACKET:
         {
            ret = EXIT_FAILURE;
            break;
         }
         case TAIR_REQ_INCDEC_PACKET:
         {
            request_inc_dec *npacket = (request_inc_dec*)packet;
            ret = req_processor->process(npacket, send_return);
            break;
         }
         case TAIR_REQ_DUPLICATE_PACKET:
         {
            request_duplicate *dpacket = (request_duplicate *)packet;
            ret = req_processor->process(dpacket, send_return);
            if (ret == TAIR_RETURN_SUCCESS) send_return = false;
            break;
         }
         case TAIR_REQ_MUPDATE_PACKET:
         {
            request_mupdate *mpacket = (request_mupdate *)(packet);
            ret = req_processor->process(mpacket, send_return);
            break;
         }
         default:
         {
            ret = EXIT_FAILURE;
            log_warn("unknow packet, pcode: %d", pcode);
         }
      }
      PROFILER_END();
      PROFILER_DUMP();
      PROFILER_STOP();

      if (ret == TAIR_RETURN_PROXYED) {
         // request is proxyed
         return false;
      }

      if (send_return && packet->get_direction() == DIRECTION_RECEIVE) {
         log_debug("send return packet, return code: %d", ret);
         tair_packet_factory::set_return_packet(packet, ret, msg, heartbeat.get_client_version());
      }

      if ((TBSYS_LOG_LEVEL_DEBUG<=TBSYS_LOGGER._level)) {
         int64_t now = tbsys::CTimeUtil::getTime();
         if (packet->get_direction() == DIRECTION_RECEIVE && now-packet->request_time>100000LL) {
            log_warn("Slow, pcode: %d, %ld us", pcode, now-packet->request_time);
         }
      }

      return true;
   }
예제 #3
0
void profiler_dump()
{
  PROFILER_DUMP();
}