Example #1
0
  private void createMasterCacheInfo() {

    LOG.info("creating master cache info");
    // check if the Cache node exists, if it doesn't create it
    NimbusMaster.getInstance().getCacheInfoLock(cacheName);
    info = NimbusMaster.getInstance().getCacheInfo(cacheName);
    if (info == null) {
      LOG.info("CacheInfo is null.  Creating CacheZNode...");
      info = new CacheInfo();
      info.setName(cacheName);
      info.setType(type);
      info.setPort(port);

      BigBitArray array =
          new BigBitArray(
              BigBitArray.makeMultipleOfEight(NimbusConf.getConf().getNumNimbusCachelets()));
      info.setAvailabilityArray(array.getBytes());

      getZooKeeper().ensurePaths(CACHE_ZNODE);
      getZooKeeper().setDataVariable(CACHE_ZNODE, info.getByteRepresentation());

      LOG.info(
          "Creating Cache ZNode at "
              + CACHE_ZNODE
              + " with data of size "
              + info.getByteRepresentation().length);
    } else {
      LOG.info("CacheInfo is not null");
    }

    NimbusMaster.getInstance().releaseCacheInfoLock(cacheName);

    if (NimbusConf.getConf().isSafetyNetEnabled()) {
      // Fire up the Safety Net
      Thread safetynet = new Thread(NimbusSafetyNet.getInstance());
      safetynet.start();
    }
  }
Example #2
0
  @Override
  public int run(String[] args) throws Exception {

    parseOptions(args);

    if (line.hasOption("start")) {
      startCache();
    } else if (line.hasOption("kill")) {
      NimbusMaster.getInstance().destroy(line.getOptionValue("kill"));
    } else {
      throw new InvalidParameterException("Unknown mode to run in.");
    }

    return 0;
  }
Example #3
0
  private void startCache() throws Exception {

    LOG.info("Starting Nimbus cache");
    Nimbus.getZooKeeper();
    LOG.info("ZooKeeper finished");

    // Set the Cache ZNode to the root + the Cache name
    CACHE_ZNODE = ROOT_ZNODE + "/" + cacheName;
    String cacheletName = InetAddress.getLocalHost().getHostName();
    CACHELET_ZNODE = CACHE_ZNODE + "/" + cacheletName;
    knownServers.put(InetAddress.getLocalHost().getHostName(), null);

    // add shutdown hook
    NimbusShutdownHook.createInstance(type);
    LOG.info("making root node");
    // ensure this root path exists
    getZooKeeper().ensurePaths(ROOT_ZNODE);

    LOG.info("done making root node");
    if (type.equals(CacheType.MASTER)) {
      createMasterCacheInfo();
    } else {
      // this info is for a non-master cache
      info = NimbusMaster.getInstance().getCacheInfo(cacheName);
      if (info == null) {
        throw new RuntimeException("No info for " + cacheName);
      }
    }

    // create my Cachelet
    switch (info.getType()) {
      case STATIC_SET:
        cachelet =
            new StaticSetCacheletServer(
                info.getName(), cacheletName, info.getPort(), info.getType());
        break;
      case DYNAMIC_SET:
        cachelet =
            new DynamicSetCacheletServer(
                info.getName(), cacheletName, info.getPort(), info.getType());
        break;
      case MASTER:
        cachelet =
            new MasterCacheletServer(info.getName(), cacheletName, info.getPort(), info.getType());
        break;
      case MAPSET:
        cachelet =
            new MapSetCacheletServer(info.getName(), cacheletName, info.getPort(), info.getType());
        break;

      case DYNAMIC_MAP:
        cachelet =
            new DynamicMapCacheletServer(
                info.getName(), cacheletName, info.getPort(), info.getType());
        break;
      default:
        LOG.error("Unkown type " + info.getType().toString() + ". Shutting down");
        System.exit(0);
    }

    Thread t = new Thread(cachelet);
    t.start();

    // add myself to ZooKeeper
    LOG.info("Creating my ZNode at " + CACHELET_ZNODE);
    getZooKeeper().ensurePaths(CACHELET_ZNODE);

    if (NimbusConf.getConf().isSafetyNetEnabled()) {
      // this while loop manages connections to other Cachelets
      // if a Cachelet connects, then create a new thread to handle
      // communication to that Cachelet and wait for more connections
      LOG.info("Starting heartbeat cycle...");
      long hbInterval = NimbusConf.getConf().getCacheletHeartbeatInterval();
      getZooKeeper().setDataVariable(CACHELET_ZNODE, BytesUtil.EMPTY_BYTES);
      while (!false) {
        Thread.sleep(hbInterval);
        getZooKeeper().setDataVariable(CACHELET_ZNODE, BytesUtil.EMPTY_BYTES);
      }
    } else {
      LOG.info("Safety net is disabled... simply sleeping this thread.");
      while (!false) {
        Thread.sleep(Integer.MAX_VALUE);
      }
    }
  }