Codota Logo
IDatabase
Code IndexAdd Codota to your IDE (free)

How to use
IDatabase
in
org.lealone.db

Best Java code snippets using org.lealone.db.IDatabase (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Point p =
  • Codota Iconnew Point(x, y)
  • Codota Iconnew Point()
  • Codota IconMouseEvent e;e.getPoint()
  • Smart code suggestions by Codota
}
origin: lealone/Lealone

private Set<NetEndpoint> getCandidateEndpoints() {
  return getCandidateEndpoints(db, db.getHostIds());
}
origin: lealone/Lealone

  private static AbstractEndpointAssignmentStrategy getEndpointAssignmentStrategy(IDatabase db) {
    if (db.getEndpointAssignmentProperties() == null)
      return defaultEndpointAssignmentStrategy;
    AbstractEndpointAssignmentStrategy endpointAssignmentStrategy = endpointAssignmentStrategies.get(db);
    if (endpointAssignmentStrategy == null) {
      HashMap<String, String> map = new HashMap<>(db.getEndpointAssignmentProperties());
      String className = map.remove("class");
      if (className == null) {
        throw new ConfigException("Missing endpoint assignment strategy class");
      }

      endpointAssignmentStrategy = AbstractEndpointAssignmentStrategy.create(db.getShortName(), className,
          ConfigDescriptor.getEndpointSnitch(), map);
      endpointAssignmentStrategies.put(db, endpointAssignmentStrategy);
    }
    return endpointAssignmentStrategy;
  }
}
origin: lealone/Lealone

boolean isShardingMode() {
  if (runMode != null) {
    return runMode == RunMode.SHARDING;
  }
  return db.isShardingMode();
}
origin: lealone/Lealone

private static AbstractReplicationStrategy getReplicationStrategy(IDatabase db) {
  if (db.getReplicationProperties() == null)
    return defaultReplicationStrategy;
  AbstractReplicationStrategy replicationStrategy = replicationStrategies.get(db);
  if (replicationStrategy == null) {
    HashMap<String, String> map = new HashMap<>(db.getReplicationProperties());
    String className = map.remove("class");
    if (className == null) {
      throw new ConfigException("Missing replication strategy class");
    }
    replicationStrategy = AbstractReplicationStrategy.createReplicationStrategy(db.getShortName(), className,
        ConfigDescriptor.getEndpointSnitch(), map);
    replicationStrategies.put(db, replicationStrategy);
  }
  return replicationStrategy;
}
origin: lealone/Lealone

Session currentSession = defineStatement.getSession();
IDatabase db = currentSession.getDatabase();
String[] hostIds = db.getHostIds();
if (hostIds.length == 0) {
  throw DbException
      .throwInternalError("DB: " + db.getShortName() + ", Run Mode: " + db.getRunMode() + ", no hostIds");
} else {
  liveMembers = new HashSet<>(hostIds.length);
if (defineStatement.isReplicationStatement() && db.isShardingMode() && !db.isStarting()) {
  List<NetEndpoint> endpoints = m.getReplicationEndpoints(db, new HashSet<>(0), liveMembers);
  if (!endpoints.isEmpty()) {
origin: lealone/Lealone

private void replicateRootPages(Object dbObject, String[] oldEndpoints, String[] targetEndpoints, RunMode runMode) {
  AOStorageService.forceMerge();
  List<NetEndpoint> replicationEndpoints = getReplicationEndpoints(targetEndpoints);
  // 用最高权限的用户移动页面,因为目标节点上可能还没有对应的数据库
  IDatabase db = (IDatabase) dbObject;
  Session session = db.createInternalSession(true);
  ReplicationSession rs = db.createReplicationSession(session, replicationEndpoints);
  int id = db.getId();
  String sysMapName = "t_" + id + "_0";
  try (DataBuffer p = DataBuffer.create(); StorageCommand c = rs.createStorageCommand()) {
    HashMap<String, StorageMap<?, ?>> maps = new HashMap<>(this.maps);
    Collection<StorageMap<?, ?>> values = maps.values();
    p.putInt(values.size());
    // SYS表放在前面,并且总是使用CLIENT_SERVER模式
    StorageMap<?, ?> sysMap = maps.remove(sysMapName);
    replicateRootPage(db, sysMap, p, oldEndpoints, RunMode.CLIENT_SERVER);
    for (StorageMap<?, ?> map : values) {
      replicateRootPage(db, map, p, oldEndpoints, runMode);
    }
    ByteBuffer pageBuffer = p.getAndFlipBuffer();
    c.replicateRootPages(db.getShortName(), pageBuffer);
    db.notifyRunModeChanged();
  }
}
origin: lealone/Lealone

@Override
public String[] getShardingEndpoints(IDatabase db) {
  HashSet<NetEndpoint> oldEndpoints = new HashSet<>();
  for (String hostId : db.getHostIds()) {
    oldEndpoints.add(P2pServer.instance.getTopologyMetaData().getEndpoint(hostId));
  }
  Set<NetEndpoint> liveMembers = Gossiper.instance.getLiveMembers();
  liveMembers.removeAll(oldEndpoints);
  ArrayList<NetEndpoint> list = new ArrayList<>(liveMembers);
  int size = liveMembers.size();
  AbstractReplicationStrategy replicationStrategy = getReplicationStrategy(db);
  int replicationFactor = replicationStrategy.getReplicationFactor();
  Map<String, String> parameters = db.getParameters();
  int nodes = replicationFactor + 2;
  if (parameters != null && parameters.containsKey("nodes")) {
    nodes = Integer.parseInt(parameters.get("nodes"));
  }
  nodes -= db.getHostIds().length;
  return getHostIds(list, size, nodes);
}
origin: lealone/Lealone

private void removeLeafPage(PageKey pageKey, BTreePage leafPage) {
  if (leafPage.getReplicationHostIds().get(0).equals(getLocalHostId())) {
    AOStorageService.submitTask(() -> {
      List<NetEndpoint> oldReplicationEndpoints = getReplicationEndpoints(leafPage);
      Set<NetEndpoint> otherEndpoints = getCandidateEndpoints();
      otherEndpoints.removeAll(oldReplicationEndpoints);
      Session session = db.createInternalSession();
      ReplicationSession rs = db.createReplicationSession(session, otherEndpoints, true);
      try (StorageCommand c = rs.createStorageCommand()) {
        c.removeLeafPage(getName(), pageKey);
      }
    });
  }
}
origin: lealone/Lealone

public String[] getHostIdsOld(IDatabase db) {
  RunMode runMode = db.getRunMode();
  Set<NetEndpoint> liveMembers = Gossiper.instance.getLiveMembers();
  ArrayList<NetEndpoint> list = new ArrayList<>(liveMembers);
  int size = liveMembers.size();
  if (runMode == RunMode.CLIENT_SERVER) {
    int i = random.nextInt(size);
    NetEndpoint addr = list.get(i);
    return new String[] { getHostId(addr) };
  } else if (runMode == RunMode.REPLICATION) {
    AbstractReplicationStrategy replicationStrategy = getReplicationStrategy(db);
    int replicationFactor = replicationStrategy.getReplicationFactor();
    return getHostIds(list, size, replicationFactor);
  } else if (runMode == RunMode.SHARDING) {
    AbstractReplicationStrategy replicationStrategy = getReplicationStrategy(db);
    int replicationFactor = replicationStrategy.getReplicationFactor();
    Map<String, String> parameters = db.getParameters();
    int nodes = replicationFactor + 2;
    if (parameters != null && parameters.containsKey("nodes")) {
      nodes = Integer.parseInt(parameters.get("nodes"));
    }
    return getHostIds(list, size, nodes);
  }
  return new String[0];
}
origin: lealone/Lealone

List<NetEndpoint> newReplicationEndpoints = db.getReplicationEndpoints(oldEndpointSet, candidateEndpoints);
Session session = db.createInternalSession();
LeafPageMovePlan leafPageMovePlan = null;
  p.setLeafPageMovePlan(leafPageMovePlan);
} else {
  ReplicationSession rs = db.createReplicationSession(session, oldReplicationEndpoints);
  try (StorageCommand c = rs.createStorageCommand()) {
    LeafPageMovePlan plan = new LeafPageMovePlan(getLocalHostId(), newReplicationEndpoints, pageKey);
  ReplicationSession rs = db.createReplicationSession(session, newReplicationEndpoints, true);
  moveLeafPage(leafPageMovePlan.pageKey, p, rs, false, !replicate);
  ReplicationSession rs = db.createReplicationSession(session, otherEndpoints, true);
  moveLeafPage(leafPageMovePlan.pageKey, p, rs, true, !replicate);
origin: lealone/Lealone

@Override
public Object replicationGet(Session session, Object key) {
  List<NetEndpoint> replicationEndpoints = getReplicationEndpoints(key);
  ReplicationSession rs = db.createReplicationSession(session, replicationEndpoints);
  try (DataBuffer k = DataBuffer.create(); StorageCommand c = rs.createStorageCommand()) {
    ByteBuffer keyBuffer = k.write(keyType, key);
    byte[] value = (byte[]) c.executeGet(getName(), keyBuffer);
    if (value == null)
      return null;
    return valueType.read(ByteBuffer.wrap(value));
  }
}
origin: lealone/Lealone

static Set<NetEndpoint> getCandidateEndpoints(IDatabase db, String[] hostIds) {
  Set<NetEndpoint> candidateEndpoints = new HashSet<>(hostIds.length);
  for (String hostId : hostIds) {
    candidateEndpoints.add(db.getEndpoint(hostId));
  }
  return candidateEndpoints;
}
origin: lealone/Lealone

switch (statement.getType()) {
case SQLStatement.CREATE_DATABASE:
  sql = db.getCreateSQL();
  break;
case SQLStatement.DROP_DATABASE:
origin: lealone/Lealone

synchronized BTreePage readRemotePage(BTreeMap<Object, Object> map) {
  if (page != null) {
    return page;
  }
  // TODO 支持多节点容错
  String remoteHostId = replicationHostIds.get(0);
  List<NetEndpoint> replicationEndpoints = BTreeMap.getReplicationEndpoints(map.db,
      new String[] { remoteHostId });
  Session session = map.db.createInternalSession(true);
  ReplicationSession rs = map.db.createReplicationSession(session, replicationEndpoints);
  try (StorageCommand c = rs.createStorageCommand()) {
    ByteBuffer pageBuffer = c.readRemotePage(map.getName(), pageKey);
    page = BTreePage.readReplicatedPage(map, pageBuffer);
  }
  if (!map.isShardingMode() || (page.getReplicationHostIds() != null
      && page.getReplicationHostIds().contains(NetEndpoint.getLocalTcpHostAndPort()))) {
    pos = 0;
  }
  return page;
}
origin: lealone/Lealone

@Override
public Object replicationAppend(Session session, Object value, StorageDataType valueType) {
  List<NetEndpoint> replicationEndpoints = getLastPageReplicationEndpoints();
  ReplicationSession rs = db.createReplicationSession(session, replicationEndpoints);
  try (DataBuffer v = DataBuffer.create(); StorageCommand c = rs.createStorageCommand()) {
    ByteBuffer valueBuffer = v.write(valueType, value);
    return c.executeAppend(null, getName(), valueBuffer, null);
  }
}
origin: lealone/Lealone

static List<NetEndpoint> getReplicationEndpoints(IDatabase db, List<String> replicationHostIds) {
  int size = replicationHostIds.size();
  List<NetEndpoint> replicationEndpoints = new ArrayList<>(size);
  for (int i = 0; i < size; i++) {
    replicationEndpoints.add(db.getEndpoint(replicationHostIds.get(i)));
  }
  return replicationEndpoints;
}
origin: lealone/Lealone

@Override
public String[] getReplicationEndpoints(IDatabase db) {
  removeReplicationStrategy(db); // 避免使用旧的
  String[] oldHostIds = db.getHostIds();
  int size = oldHostIds.length;
  List<NetEndpoint> oldReplicationEndpoints = new ArrayList<>(size);
  for (int i = 0; i < size; i++) {
    oldReplicationEndpoints.add(P2pServer.instance.getTopologyMetaData().getEndpoint(oldHostIds[i]));
  }
  List<NetEndpoint> newReplicationEndpoints = getLiveReplicationEndpoints(db,
      new HashSet<>(oldReplicationEndpoints), Gossiper.instance.getLiveMembers(), true);
  size = newReplicationEndpoints.size();
  String[] hostIds = new String[size];
  int j = 0;
  for (NetEndpoint e : newReplicationEndpoints) {
    String hostId = getHostId(e);
    if (hostId != null)
      hostIds[j++] = hostId;
  }
  return hostIds;
}
origin: lealone/Lealone

private Object putRemote(BTreePage p, Object key, Object value) {
  if (p.getLeafPageMovePlan().moverHostId.equals(getLocalHostId())) {
    int size = p.getLeafPageMovePlan().replicationEndpoints.size();
    List<NetEndpoint> replicationEndpoints = new ArrayList<>(size);
    replicationEndpoints.addAll(p.getLeafPageMovePlan().replicationEndpoints);
    boolean containsLocalEndpoint = replicationEndpoints.remove(getLocalEndpoint());
    Object returnValue = null;
    ReplicationSession rs = db.createReplicationSession(db.createInternalSession(), replicationEndpoints);
    try (DataBuffer k = DataBuffer.create();
        DataBuffer v = DataBuffer.create();
        StorageCommand c = rs.createStorageCommand()) {
      ByteBuffer keyBuffer = k.write(keyType, key);
      ByteBuffer valueBuffer = v.write(valueType, value);
      byte[] oldValue = (byte[]) c.executePut(null, getName(), keyBuffer, valueBuffer, true);
      if (oldValue != null) {
        returnValue = valueType.read(ByteBuffer.wrap(oldValue));
      }
    }
    // 如果新的复制节点中还包含本地节点,那么还需要put到本地节点中
    if (containsLocalEndpoint) {
      return putLocal(p, key, value);
    } else {
      return returnValue;
    }
  } else {
    return null; // 不是由当前节点移动的,那么put操作就可以忽略了
  }
}
origin: lealone/Lealone

@Override
public Object replicationPut(Session session, Object key, Object value, StorageDataType valueType) {
  List<NetEndpoint> replicationEndpoints = getReplicationEndpoints(key);
  ReplicationSession rs = db.createReplicationSession(session, replicationEndpoints);
  try (DataBuffer k = DataBuffer.create();
      DataBuffer v = DataBuffer.create();
      StorageCommand c = rs.createStorageCommand()) {
    ByteBuffer keyBuffer = k.write(keyType, key);
    ByteBuffer valueBuffer = v.write(valueType, value);
    byte[] oldValue = (byte[]) c.executePut(null, getName(), keyBuffer, valueBuffer, false);
    if (oldValue == null)
      return null;
    return valueType.read(ByteBuffer.wrap(oldValue));
  }
}
origin: lealone/Lealone

private List<NetEndpoint> getReplicationEndpoints(List<String> replicationHostIds) {
  int size = replicationHostIds.size();
  List<NetEndpoint> replicationEndpoints = new ArrayList<>(size);
  for (int i = 0; i < size; i++) {
    replicationEndpoints.add(db.getEndpoint(replicationHostIds.get(i)));
  }
  return replicationEndpoints;
}
org.lealone.dbIDatabase

Most used methods

  • getHostIds
  • getShortName
  • getRunMode
  • isShardingMode
  • createInternalSession
  • createReplicationSession
  • getCreateSQL
  • getEndpoint
  • getEndpointAssignmentProperties
  • getHostId
  • getId
  • getLocalHostId
  • getId,
  • getLocalHostId,
  • getParameters,
  • getReplicationEndpoints,
  • getReplicationProperties,
  • getStorages,
  • isStarting,
  • notifyRunModeChanged

Popular in Java

  • Start an intent from android
  • setContentView (Activity)
  • requestLocationUpdates (LocationManager)
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • IOException (java.io)
    Signals that an I/O exception of some sort has occurred. This class is the general class of exceptio
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • PriorityQueue (java.util)
    An unbounded priority Queue based on a priority heap. The elements of the priority queue are ordered
  • BoxLayout (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now