Skip to content

Commit

Permalink
improve performance for table with large number of columns per row
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Cher committed Dec 25, 2013
1 parent 731d8b6 commit c3f01f7
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 86 deletions.
9 changes: 0 additions & 9 deletions src/main/java/hrider/config/ClusterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public ConnectionDetails getConnection() {
public void setConnection(ConnectionDetails connection) {
set("connection.zookeeper.host", connection.getZookeeper().getHost());
set("connection.zookeeper.port", connection.getZookeeper().getPort());

save();
}

/**
Expand Down Expand Up @@ -117,7 +115,6 @@ public <T> T getTableConfig(Class<T> clazz, String table, String column, String
*/
public void setTableConfig(String table, String value) {
set(String.format("table.%s", table), value);
save();
}

/**
Expand All @@ -129,7 +126,6 @@ public void setTableConfig(String table, String value) {
*/
public void setTableConfig(String table, String key, String value) {
set(String.format("table.%s.%s", table, key), value);
save();
}

/**
Expand All @@ -142,7 +138,6 @@ public void setTableConfig(String table, String key, String value) {
*/
public void setTableConfig(String table, String column, String key, String value) {
set(String.format("table.%s.%s.%s", table, column, key), value);
save();
}

/**
Expand Down Expand Up @@ -208,7 +203,6 @@ public void setTablesFilter(Iterable<String> filters) {
}

set("table.filters", sb.toString());
save();
}

/**
Expand All @@ -218,7 +212,6 @@ public void setTablesFilter(Iterable<String> filters) {
*/
public void setSelectedTableFilter(String filter) {
set("table.filters.selected", filter);
save();
}

/**
Expand All @@ -237,7 +230,6 @@ public void setColumnsFilter(String table, Iterable<String> filters) {
}

set(String.format("table.%s.column.filters", table), sb.toString());
save();
}

/**
Expand All @@ -248,7 +240,6 @@ public void setColumnsFilter(String table, Iterable<String> filters) {
*/
public void setSelectedColumnFilter(String table, String filter) {
set(String.format("table.%s.column.filters.selected", table), filter);
save();
}
//endregion
}
25 changes: 16 additions & 9 deletions src/main/java/hrider/hbase/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* <p/>
* This class represents a scanner over the hbase tables.
*/
@SuppressWarnings({"OverlyNestedMethod", "ClassWithTooManyMethods"})
public class Scanner {

//region Variables
Expand Down Expand Up @@ -286,8 +287,8 @@ public DataRow getFirstRow() throws IOException {
ResultScanner scanner = table.getScanner(scan);

try {
Collection<DataRow> rows = new ArrayList<DataRow>();
Collection<ColumnQualifier> columns = new ArrayList<ColumnQualifier>();
Collection<DataRow> rows = new LinkedList<DataRow>();
Collection<ColumnQualifier> columns = new LinkedList<ColumnQualifier>();

columns.add(ColumnQualifier.KEY);

Expand Down Expand Up @@ -470,7 +471,9 @@ protected boolean isValidRow(Result row) {
*/
protected ConvertibleObject loadRows(
ResultScanner scanner, long offset, int rowsNumber, Collection<DataRow> rows, Collection<ColumnQualifier> columns) throws IOException {

ColumnType keyType = this.columnTypes.get(ColumnQualifier.KEY.getName());
Map<ColumnQualifier, ColumnQualifier> loadedColumns = new HashMap<ColumnQualifier, ColumnQualifier>();

int index = 0;
boolean isValid;
Expand Down Expand Up @@ -499,19 +502,20 @@ protected ConvertibleObject loadRows(
for (NavigableMap.Entry<byte[], NavigableMap<Long, byte[]>> qualifierEntry : familyEntry.getValue().entrySet()) {
ColumnQualifier qualifier = new ColumnQualifier(qualifierEntry.getKey(), new ColumnFamily(columnDescriptor), nameConverter);

ColumnType columnType = ColumnType.String;
String columnName = qualifier.getFullName();
ColumnType columnType = this.columnTypes.get(columnName);

if (this.columnTypes.containsKey(columnName)) {
columnType = this.columnTypes.get(columnName);
if (columnType == null) {
columnType = ColumnType.String;
}

for (NavigableMap.Entry<Long, byte[]> cell : qualifierEntry.getValue().entrySet()) {
row.addCell(new DataCell(row, qualifier, new ConvertibleObject(columnType, cell.getValue())));
}

if (!columns.contains(qualifier)) {
if (!loadedColumns.containsKey(qualifier)) {
columns.add(qualifier);
loadedColumns.put(qualifier, null);
}
}
}
Expand All @@ -537,6 +541,8 @@ private Collection<ColumnQualifier> loadColumns(int rowsNumber) throws IOExcepti
Collection<ColumnQualifier> columns = new ArrayList<ColumnQualifier>();
columns.add(ColumnQualifier.KEY);

Map<ColumnQualifier, ColumnQualifier> loadedColumns = new HashMap<ColumnQualifier, ColumnQualifier>();

int itemsNumber = rowsNumber <= GlobalConfig.instance().getBatchSizeForRead() ? rowsNumber : GlobalConfig.instance().getBatchSizeForRead();

Scan scan = getScanner();
Expand All @@ -561,8 +567,9 @@ private Collection<ColumnQualifier> loadColumns(int rowsNumber) throws IOExcepti

for (byte[] quantifier : familyEntry.getValue().keySet()) {
ColumnQualifier columnQualifier = new ColumnQualifier(quantifier, new ColumnFamily(columnDescriptor), nameConverter);
if (!columns.contains(columnQualifier)) {
if (!loadedColumns.containsKey(columnQualifier)) {
columns.add(columnQualifier);
loadedColumns.put(columnQualifier, null);
}
}
}
Expand Down Expand Up @@ -606,8 +613,8 @@ private Collection<DataRow> next(long offset, int rowsNumber) throws IOException
ResultScanner scanner = table.getScanner(scan);

try {
Collection<DataRow> rows = new ArrayList<DataRow>();
Collection<ColumnQualifier> columns = new ArrayList<ColumnQualifier>();
Collection<DataRow> rows = new LinkedList<DataRow>();
Collection<ColumnQualifier> columns = new LinkedList<ColumnQualifier>();

columns.add(ColumnQualifier.KEY);

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/hrider/ui/TabActionListener.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package hrider.ui;

import hrider.ui.views.DesignerView;

import javax.swing.*;
import java.awt.*;

/**
* Copyright (C) 2012 NICE Systems ltd.
Expand All @@ -28,10 +29,10 @@ public interface TabActionListener {
/**
* The method is called each time the tab of {@link JTabbedPane} is closed by the user.
*/
void onTabClosed();
void onTabClosed(DesignerView closingView);

/**
* The method is called each time the tab of {@link JTabbedPane} is being duplicated by the user.
*/
void onTabDuplicated();
void onTabDuplicated(DesignerView sourceView);
}
9 changes: 5 additions & 4 deletions src/main/java/hrider/ui/controls/JTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hrider.ui.Images;
import hrider.ui.TabActionListener;
import hrider.ui.views.DesignerView;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -41,7 +42,7 @@ public class JTab extends JPanel {
//endregion

//region Constructor
public JTab(final String title, final JTabbedPane pane) {
public JTab(String title, final DesignerView view, final JTabbedPane pane) {

setOpaque(false);

Expand All @@ -64,10 +65,10 @@ public JTab(final String title, final JTabbedPane pane) {
@Override
public void actionPerformed(ActionEvent e) {
if (pane.getTabCount() > 1) {
pane.removeTabAt(pane.indexOfTab(title));
pane.removeTabAt(pane.indexOfComponent(view.getView()));

for (TabActionListener listener : listeners) {
listener.onTabClosed();
listener.onTabClosed(view);
}
}
}
Expand All @@ -85,7 +86,7 @@ public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {
for (TabActionListener listener : listeners) {
listener.onTabDuplicated();
listener.onTabDuplicated(view);
}
}
});
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/hrider/ui/design/JListRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof String) {
try {
if (TableUtil.isMetaTable((String)value)) {
setForeground(Color.darkGray);
}
else if (!connection.tableEnabled((String)value)) {
setForeground(Color.gray);
if (isSelected || cellHasFocus) {
if (TableUtil.isMetaTable((String)value)) {
setForeground(Color.darkGray);
}
else if (!connection.tableEnabled((String)value)) {
setForeground(Color.gray);
}
}
}
catch (Exception ignore) {
Expand Down
47 changes: 32 additions & 15 deletions src/main/java/hrider/ui/forms/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.net.URL;
Expand Down Expand Up @@ -268,13 +269,21 @@ public void run() {
* event-dispatching thread.
*/
private static void createAndShowGUI() {
Window window = new Window();
final Window window = new Window();
window.loadViews(new Splash());

if (!window.canceled) {
JFrame frame = new JFrame("h-rider - " + getVersion());
window.frame = frame;

frame.addWindowListener(
new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
window.saveViews();
}
});

frame.setContentPane(window.topPanel);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocationByPlatform(true);
Expand Down Expand Up @@ -433,13 +442,21 @@ public void run() {
}
}

private void saveViews() {
for (List<DesignerView> views : viewList.values()) {
for (DesignerView view : views) {
view.saveView();
}
}
}

/**
* Loads a single cluster view.
*
* @param connection A connection to be used to connect to the cluster.
*/
private DesignerView loadView(int index, final Connection connection) {
final DesignerView view = new DesignerView(this.topPanel, connection);
DesignerView view = new DesignerView(this.topPanel, connection);

List<DesignerView> views = viewList.get(connection.getServerName());
if (views == null) {
Expand All @@ -449,41 +466,41 @@ private DesignerView loadView(int index, final Connection connection) {

views.add(view);

final JTab tab = new JTab(connection.getServerName(), this.tabbedPane);
JTab tab = new JTab(connection.getServerName(), view, this.tabbedPane);
tab.addTabActionListener(
new TabActionListener() {
@Override
public void onTabClosed() {
List<DesignerView> list = viewList.get(view.getConnection().getServerName());
list.remove(view);
public void onTabClosed(DesignerView closingView) {
List<DesignerView> list = viewList.get(closingView.getConnection().getServerName());
list.remove(closingView);

ClipboardData<DataTable> data = InMemoryClipboard.getData();
if (data != null) {
Connection helper = data.getData().getConnection();
if (helper != null) {
if (helper.equals(view.getConnection())) {
if (helper.equals(closingView.getConnection())) {
InMemoryClipboard.setData(null);
}
}
}

if (list.isEmpty()) {
ViewConfig.instance().removeCluster(view.getConnection().getServerName());
PropertiesConfig.fileRemove(view.getConnection().getServerName());
ViewConfig.instance().removeCluster(closingView.getConnection().getServerName());
PropertiesConfig.fileRemove(closingView.getConnection().getServerName());

viewList.remove(view.getConnection().getServerName());
viewList.remove(closingView.getConnection().getServerName());
}

ConnectionManager.release(view.getConnection().getConnectionDetails());
ConnectionManager.release(closingView.getConnection().getConnectionDetails());
}

@Override
public void onTabDuplicated() {
public void onTabDuplicated(DesignerView sourceView) {
try {
int newIndex = tabbedPane.indexOfComponent(view.getView());
int newIndex = tabbedPane.indexOfComponent(sourceView.getView());

DesignerView duplicatedView = loadView(newIndex + 1, new Connection(connection.getConnectionDetails()));
duplicatedView.setSelectedTableName(view.getSelectedTableName());
duplicatedView.setSelectedTableName(sourceView.getSelectedTableName());
}
catch (IOException ex) {
MessageHandler.addError(String.format("Failed to duplicate view for %s.", connection.getServerName()), ex);
Expand All @@ -506,7 +523,7 @@ public void onTabDuplicated() {
/**
* Shows a connection dialog.
*
* @return A reference to {@link ConnectionDetails} class that contains all required information to connect to the cluster.
* @return A reference to {@link hrider.config.ConnectionDetails} class that contains all required information to connect to the cluster.
*/
private ConnectionDetails showDialog() {
ConnectionDetailsDialog dialog = new ConnectionDetailsDialog();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/hrider/ui/views/DesignerView.form
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@
<component id="24118" class="javax.swing.JTable" binding="columnsTable">
<constraints/>
<properties>
<autoCreateRowSorter value="true"/>
<autoResizeMode value="1"/>
</properties>
</component>
Expand Down
Loading

0 comments on commit c3f01f7

Please sign in to comment.