Skip to content

Commit

Permalink
Merge branch '3.8' of https://github.com/JumpMind/symmetric-ds into 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Apr 27, 2017
2 parents b56ea77 + 36f3b7c commit f6c4b32
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 11 deletions.
7 changes: 5 additions & 2 deletions symmetric-assemble/src/asciidoc/installation.ad
Expand Up @@ -263,8 +263,11 @@ bin/sym_service stop

A single SymmetricDS node may be clustered across a series of instances, creating a web farm. A node might be clustered to provide load balancing and failover, for example.

When clustered, a hardware load balancer is typically used
to round robin client requests to the cluster. The load balancer should be configured for stateless connections.
When clustered, a hardware load balancer is typically used.

For clustered nodes running SymmetricDS 3.8 and later the recommended approach is to configure the load balancer to use sticky sessions or ensure the staging directory for all nodes in the cluster are using a shared network drive.

For clustered nodes running SymmetricDS 3.7 and earlier it is recommended to round robin client requests to the cluster and configure the load balancer for stateless connections.

ifndef::pro[]
Also, the `sync.url` (discussed in <<Node Properties File>>) SymmetricDS property should be set to the URL of the load balancer.
Expand Down
Expand Up @@ -152,7 +152,7 @@ public void exportTestDatabaseSQL() throws Exception {
return;
}

final int EXPECTED_VARCHAR_MAX_COUNT = engine.getDatabasePlatform().getName().equals(DatabaseNamesConstants.SQLITE) ? 293 : 50;
final int EXPECTED_VARCHAR_MAX_COUNT = engine.getDatabasePlatform().getName().equals(DatabaseNamesConstants.SQLITE) ? 294 : 50;
final String EXPECTED_VARCHAR_MAX_STRING = "varchar(" + Integer.MAX_VALUE + ")";
final int actualVarcharMaxCount = StringUtils.countMatches(output, EXPECTED_VARCHAR_MAX_STRING);
String msg = String.format("Expected %s, but got %s in the following output %s",
Expand Down
Expand Up @@ -32,6 +32,8 @@
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.GZIPInputStream;

import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -60,13 +62,18 @@
public class HttpTransportManager extends AbstractTransportManager implements ITransportManager {

private ISymmetricEngine engine;
private AtomicReference<String> cachedHostName = new AtomicReference<String>();
private AtomicReference<String> cachedIpAddress = new AtomicReference<String>();
private AtomicLong cacheTime = new AtomicLong(-1);
private long hostCacheTtl = 0;

public HttpTransportManager() {
}

public HttpTransportManager(ISymmetricEngine engine) {
super(engine.getExtensionService());
this.engine = engine;
hostCacheTtl = engine.getParameterService().getLong("cache.security.token.host.time.ms", 5*60*1000);
}

public int sendCopyRequest(Node local) throws IOException {
Expand Down Expand Up @@ -328,10 +335,42 @@ protected String addSecurityToken(String base, String connector, String nodeId,
sb.append(WebConstants.SECURITY_TOKEN);
sb.append("=");
sb.append(securityToken);
append(sb, WebConstants.HOST_NAME, AppUtils.getHostName());
append(sb, WebConstants.IP_ADDRESS, AppUtils.getIpAddress());
String[] hostAndIpAddress = getHostAndIpAddress();
append(sb, WebConstants.HOST_NAME, hostAndIpAddress[0]);
append(sb, WebConstants.IP_ADDRESS, hostAndIpAddress[1]);
return sb.toString();
}

protected String[] getHostAndIpAddress() {
String hostName, ipAddress;
if (cachedHostName.get() == null || cachedIpAddress.get() == null || cacheTimeExpired(cacheTime)) {
cachedHostName.set(null);
cachedIpAddress.set(null);
hostName = AppUtils.getHostName();
ipAddress = AppUtils.getIpAddress();
if (!StringUtils.isEmpty(hostName) && !"unknown".equals(hostName)) {
cachedHostName.set(hostName);
}
if (!StringUtils.isEmpty(ipAddress) && !"unknown".equals(ipAddress)) {
cachedIpAddress.set(ipAddress);
}
cacheTime.set(System.currentTimeMillis());
} else {
hostName = cachedHostName.get();
ipAddress = cachedIpAddress.get();
}

return new String[] {hostName, ipAddress};
}

protected boolean cacheTimeExpired(AtomicLong argCacheTime) {
long cacheTimeLong = argCacheTime.get();
if (cacheTimeLong == -1 || (System.currentTimeMillis()-cacheTimeLong) > hostCacheTtl) {
return true;
} else {
return false;
}
}

protected String addNodeId(String base, String nodeId, String connector) {
return add(base, WebConstants.NODE_ID, nodeId, connector);
Expand Down
Expand Up @@ -2045,7 +2045,11 @@ protected void printDefaultValue(String defaultValue, int typeCode, StringBuilde
|| defaultValueStr.toUpperCase().startsWith("CURRENT_TIMESTAMP")
|| defaultValueStr.toUpperCase().startsWith("CURRENT_TIME")
|| defaultValueStr.toUpperCase().startsWith("CURRENT_DATE")
|| defaultValueStr.toUpperCase().startsWith("CURRENT TIMESTAMP")
|| defaultValueStr.toUpperCase().startsWith("CURRENT TIME")
|| defaultValueStr.toUpperCase().startsWith("CURRENT DATE")
|| defaultValueStr.toUpperCase().startsWith("CURRENT_USER")
|| defaultValueStr.toUpperCase().startsWith("CURRENT USER")
|| defaultValueStr.toUpperCase().startsWith("USER")
|| defaultValueStr.toUpperCase().startsWith("SYSTEM_USER")
|| defaultValueStr.toUpperCase().startsWith("SESSION_USER")
Expand Down
Expand Up @@ -319,6 +319,9 @@ protected String getSqlType(Column column) {
&& (column.getMappedTypeCode() == Types.DECIMAL || column.getMappedTypeCode() == Types.NUMERIC)) {
sqlType = "BIGINT";
}
if (column.getMappedTypeCode() == Types.TIMESTAMP && column.getScale() > 0) {
sqlType = "TIMESTAMP(" + column.getScale() + ")";
}
return sqlType;
}

Expand Down
Expand Up @@ -697,10 +697,10 @@ protected Table readTable(Connection connection, DatabaseMetaDataWrapper metaDat
}
return table;
} catch (RuntimeException ex) {
log.error("Failed to read table: {}", tableName);
log.error(String.format("Failed to read table: %s. Error: %s", tableName, ex.getMessage()));
throw ex;
} catch (SQLException ex) {
log.error("Failed to read table: {}", tableName);
log.error(String.format("Failed to read table: %s. Error: %s", tableName, ex.getMessage()));
throw ex;
}
}
Expand Down
@@ -1,5 +1,7 @@
package org.jumpmind.db.platform.mysql;

import java.sql.Types;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -22,6 +24,10 @@
import javax.sql.DataSource;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.Database;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.model.TypeMap;
import org.jumpmind.db.platform.AbstractJdbcDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.platform.PermissionResult;
Expand Down Expand Up @@ -132,4 +138,22 @@ public PermissionResult getCreateSymRoutinePermission() {
}
return result;
}

@Override
public void makePlatformSpecific(Database database) {
for (Table table : database.getTables()) {
for (Column column : table.getColumns()) {
try {
if (column.getMappedTypeCode() == Types.DATE
&& column.findPlatformColumn(DatabaseNamesConstants.ORACLE) != null) {
column.setMappedType(TypeMap.TIMESTAMP);
column.setMappedTypeCode(Types.TIMESTAMP);
column.setScale(6);
}
}
catch (Exception e) {}
}
}
super.makePlatformSpecific(database);
}
}
Expand Up @@ -101,14 +101,20 @@ protected Integer mapUnknownJdbcTypeForColumn(Map<String, Object> values) {
String collation = platform.getSqlTemplate().queryForString("select collation_name from information_schema.columns " +
"where table_schema = ? and table_name = ? and column_name = ?",
catalog, tableName, columnName);
boolean isBinary = collation != null && collation.equalsIgnoreCase("utf8_bin");

String convertTextToLobParm = System.getProperty("mysqlddlreader.converttexttolob",
"true");
boolean convertTextToLob = collation != null && collation.endsWith("_bin") &&
convertTextToLobParm.equalsIgnoreCase("true");

if ("LONGTEXT".equals(typeName)) {
return isBinary ? Types.BLOB : Types.CLOB;
return convertTextToLob ? Types.BLOB : Types.CLOB;
} else if ("MEDIUMTEXT".equals(typeName)) {
return isBinary ? Types.BLOB : Types.LONGVARCHAR;
return convertTextToLob ? Types.BLOB : Types.LONGVARCHAR;
} else if ("TEXT".equals(typeName)) {
return convertTextToLob ? Types.BLOB : Types.LONGVARCHAR;
} else if ("TINYTEXT".equals(typeName)) {
return isBinary ? Types.BLOB : Types.LONGVARCHAR;
return convertTextToLob ? Types.BLOB : Types.LONGVARCHAR;
}
return super.mapUnknownJdbcTypeForColumn(values);
} else if (type != null && type == Types.OTHER) {
Expand Down

0 comments on commit f6c4b32

Please sign in to comment.