obwriter: adapted for short jdbc url

This commit is contained in:
江煦 2021-09-24 18:03:38 +08:00
parent c0351b8d76
commit 26d1f11c1b
3 changed files with 25 additions and 5 deletions

View File

@ -20,7 +20,6 @@ import com.alibaba.datax.plugin.rdbms.writer.Constant;
import com.alibaba.datax.plugin.rdbms.writer.Key; import com.alibaba.datax.plugin.rdbms.writer.Key;
import com.alibaba.datax.plugin.rdbms.writer.util.WriterUtil; import com.alibaba.datax.plugin.rdbms.writer.util.WriterUtil;
import com.alibaba.datax.plugin.writer.oceanbasev10writer.task.ConcurrentTableWriterTask; import com.alibaba.datax.plugin.writer.oceanbasev10writer.task.ConcurrentTableWriterTask;
import com.alibaba.datax.plugin.writer.oceanbasev10writer.task.SingleTableWriterTask;
import com.alibaba.datax.plugin.writer.oceanbasev10writer.util.ObWriterUtils; import com.alibaba.datax.plugin.writer.oceanbasev10writer.util.ObWriterUtils;
/** /**

View File

@ -24,8 +24,26 @@ public class ServerConnectInfo {
this.tenantName = ss[1].trim().split(":")[1]; this.tenantName = ss[1].trim().split(":")[1];
this.jdbcUrl = ss[2].replace("jdbc:mysql:", "jdbc:oceanbase:"); this.jdbcUrl = ss[2].replace("jdbc:mysql:", "jdbc:oceanbase:");
} else { } else {
throw new RuntimeException ("jdbc url format is not correct: " + jdbcUrl); this.jdbcUrl = jdbcUrl.replace("jdbc:mysql:", "jdbc:oceanbase:");
if (username.contains("@") && username.contains("#")) {
this.userName = username.substring(0, username.indexOf("@"));
this.tenantName = username.substring(username.indexOf("@") + 1, username.indexOf("#"));
this.clusterName = username.substring(username.indexOf("#") + 1);
} else if (username.contains(":")) {
String[] config = username.split(":");
if (config.length != 3) {
throw new RuntimeException ("username format is not correct: " + username);
}
this.clusterName = config[0];
this.tenantName = config[1];
this.userName = config[2];
} else {
this.clusterName = null;
this.tenantName = null;
this.userName = username;
}
} }
this.password = password; this.password = password;
parseJdbcUrl(jdbcUrl); parseJdbcUrl(jdbcUrl);
} }
@ -51,8 +69,11 @@ public class ServerConnectInfo {
} }
public String getFullUserName() { public String getFullUserName() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder(userName);
builder.append(userName).append("@").append(tenantName).append("#").append(clusterName); if (tenantName != null && clusterName != null) {
builder.append("@").append(tenantName).append("#").append(clusterName);
}
return builder.toString(); return builder.toString();
} }
} }

View File

@ -150,7 +150,7 @@ public class ConcurrentTableWriterTask extends CommonRdbmsWriter.Task {
partCalculator = new ObPartitionIdCalculator(connectInfo.ipPort, tableEntryKey); partCalculator = new ObPartitionIdCalculator(connectInfo.ipPort, tableEntryKey);
} catch (Exception ex) { } catch (Exception ex) {
++retry; ++retry;
LOG.warn("create new part calculator failed, retry ... {}", retry, ex); LOG.warn("create new part calculator failed, retry {}: {}", retry, ex.getMessage());
} }
} while (partCalculator == null && retry < 3); // try 3 times } while (partCalculator == null && retry < 3); // try 3 times
} }