Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/querying/sql-metadata-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Servers table lists all discovered servers in the cluster.
|current_size|BIGINT|Current size of segments in bytes on this server. Only valid for HISTORICAL type, for other types it's 0|
|max_size|BIGINT|Max size in bytes this server recommends to assign to segments see [druid.server.maxSize](../configuration/index.md#historical-general-configuration). Only valid for HISTORICAL type, for other types it's 0|
|is_leader|BIGINT|1 if the server is currently the 'leader' (for services which have the concept of leadership), otherwise 0 if the server is not the leader, or the default long value (0 or null depending on `druid.generic.useDefaultValueForNull`) if the server type does not have the concept of leadership|

|start_time|STRING|Timestamp in ISO8601 format when the server was announced in the cluster|
To retrieve information about all servers, use the query:

```sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void test_systemSchemaAccess_admin() throws Exception
verifySystemSchemaServerQuery(
adminClient,
SYS_SCHEMA_SERVERS_QUERY,
getServersWithoutCurrentSize(adminServers)
getServersWithoutCurrentSizeAndStartTime(adminServers)
);

LOG.info("Checking sys.server_segments query as admin...");
Expand Down Expand Up @@ -767,7 +767,7 @@ protected void verifySystemSchemaQueryBase(
String content = responseHolder.getContent();
List<Map<String, Object>> responseMap = jsonMapper.readValue(content, SYS_SCHEMA_RESULTS_TYPE_REFERENCE);
if (isServerQuery) {
responseMap = getServersWithoutCurrentSize(responseMap);
responseMap = getServersWithoutCurrentSizeAndStartTime(responseMap);
}
Assert.assertEquals(responseMap, expectedResults);
}
Expand Down Expand Up @@ -914,7 +914,7 @@ protected void setExpectedSystemSchemaObjects() throws IOException
SYS_SCHEMA_RESULTS_TYPE_REFERENCE
);

adminServers = getServersWithoutCurrentSize(
adminServers = getServersWithoutCurrentSizeAndStartTime(
jsonMapper.readValue(
fillServersTemplate(
config,
Expand All @@ -937,13 +937,14 @@ protected void setExpectedSystemSchemaObjects() throws IOException
* curr_size on historicals changes because cluster state is not isolated across different
* integration tests, zero it out for consistent test results
*/
protected static List<Map<String, Object>> getServersWithoutCurrentSize(List<Map<String, Object>> servers)
protected static List<Map<String, Object>> getServersWithoutCurrentSizeAndStartTime(List<Map<String, Object>> servers)
{
return Lists.transform(
servers,
(server) -> {
Map<String, Object> newServer = new HashMap<>(server);
newServer.put("curr_size", 0);
newServer.put("start_time", "0");
return newServer;
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"tier": "_default_tier",
"curr_size": 2208932412,
"max_size": 5000000000,
"is_leader": %%NON_LEADER%%
"is_leader": %%NON_LEADER%%,
"start_time": "0"
},
{
"server": "%%BROKER%%:8282",
Expand All @@ -19,6 +20,7 @@
"tier": "_default_tier",
"curr_size": 0,
"max_size": 1000000000,
"is_leader": %%NON_LEADER%%
"is_leader": %%NON_LEADER%%,
"start_time": "0"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import org.apache.druid.jackson.StringObjectPairList;
import org.apache.druid.java.util.common.DateTimes;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.NonnullPair;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.server.DruidNode;
import org.joda.time.DateTime;

import javax.annotation.Nullable;
import java.util.HashMap;
Expand All @@ -50,6 +52,7 @@ public class DiscoveryDruidNode

private final DruidNode druidNode;
private final NodeRole nodeRole;
private final DateTime startTime;

/**
* Map of service name -> DruidServices.
Expand All @@ -66,20 +69,32 @@ public DiscoveryDruidNode(
NodeRole nodeRole,
Map<String, DruidService> services
)
{
this(druidNode, nodeRole, services, DateTimes.nowUtc());
}

public DiscoveryDruidNode(
DruidNode druidNode,
NodeRole nodeRole,
Map<String, DruidService> services,
DateTime startTime
)
{
this.druidNode = druidNode;
this.nodeRole = nodeRole;

if (services != null && !services.isEmpty()) {
this.services.putAll(services);
}
this.startTime = startTime;
}

@JsonCreator
private static DiscoveryDruidNode fromJson(
@JsonProperty("druidNode") DruidNode druidNode,
@JsonProperty("nodeType") NodeRole nodeRole,
@JsonProperty("services") Map<String, StringObjectPairList> rawServices,
@JsonProperty("startTime") DateTime startTime,
@JacksonInject ObjectMapper jsonMapper
)
{
Expand All @@ -95,7 +110,7 @@ private static DiscoveryDruidNode fromJson(
}
}
}
return new DiscoveryDruidNode(druidNode, nodeRole, services);
return new DiscoveryDruidNode(druidNode, nodeRole, services, startTime);
}

/**
Expand All @@ -106,10 +121,10 @@ private static DiscoveryDruidNode fromJson(
* This is definitely a bug of DataNodeService, but, since renaming one of those duplicate keys will
* break compatibility, DataNodeService still has the deprecated "type" property.
* See the Javadoc of DataNodeService for more details.
*
* <p>
* This function catches such duplicate keys and rewrites the deprecated "type" to "serverType",
* so that we don't lose any properties.
*
* <p>
* This method can be removed together when we entirely remove the deprecated "type" property from DataNodeService.
*/
@Deprecated
Expand Down Expand Up @@ -166,6 +181,12 @@ public DruidNode getDruidNode()
return druidNode;
}

@JsonProperty
public DateTime getStartTime()
{
return startTime;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is startTime omitted while verifying the equality of this class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a DiscoveryDruidNode object is primarily identified by its DruidNode, role and the service map, I wanted to preserve the equality condition. Also, start_time might not be a concrete enough to decide the equality between two DiscoveryDruidNode objects, if the other field values are the same. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation! I think it's better to keep it the current way.


@Nullable
@JsonIgnore
public <T extends DruidService> T getService(String key, Class<T> clazz)
Expand Down Expand Up @@ -205,7 +226,8 @@ public String toString()
return "DiscoveryDruidNode{" +
"druidNode=" + druidNode +
", nodeRole='" + nodeRole + '\'' +
", services=" + services +
", services=" + services + '\'' +
", startTime=" + startTime +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void testEquals()
{
EqualsVerifier.forClass(DiscoveryDruidNode.class)
.withNonnullFields("druidNode", "nodeRole", "services")
.withIgnoredFields("startTime")
.usingGetClass()
.verify();
}
Expand Down
12 changes: 6 additions & 6 deletions services/src/main/java/org/apache/druid/cli/CliOverlord.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ public void configure(Binder binder)

if (standalone) {
LifecycleModule.register(binder, Server.class);
}

bindAnnouncer(
binder,
IndexingService.class,
DiscoverySideEffectsProvider.create()
);
bindAnnouncer(
binder,
IndexingService.class,
DiscoverySideEffectsProvider.create()
);
}

Jerseys.addResource(binder, SelfDiscoveryResource.class);
LifecycleModule.registerKey(binder, Key.get(SelfDiscoveryResource.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public class SystemSchema extends AbstractSchema
.add("curr_size", ColumnType.LONG)
.add("max_size", ColumnType.LONG)
.add("is_leader", ColumnType.LONG)
.add("start_time", ColumnType.STRING)
.build();

static final RowSignature SERVER_SEGMENTS_SIGNATURE = RowSignature
Expand Down Expand Up @@ -595,7 +596,8 @@ private static Object[] buildRowForNonDataServer(DiscoveryDruidNode discoveryDru
null,
UNKNOWN_SIZE,
UNKNOWN_SIZE,
NullHandling.defaultLongValue()
NullHandling.defaultLongValue(),
toStringOrNull(discoveryDruidNode.getStartTime())
};
}

Expand All @@ -614,7 +616,8 @@ private static Object[] buildRowForNonDataServerWithLeadership(DiscoveryDruidNod
null,
UNKNOWN_SIZE,
UNKNOWN_SIZE,
isLeader ? 1L : 0L
isLeader ? 1L : 0L,
toStringOrNull(discoveryDruidNode.getStartTime())
};
}

Expand Down Expand Up @@ -648,7 +651,8 @@ private static Object[] buildRowForDiscoverableDataServer(
druidServerToUse.getTier(),
currentSize,
druidServerToUse.getMaxSize(),
NullHandling.defaultLongValue()
NullHandling.defaultLongValue(),
toStringOrNull(discoveryDruidNode.getStartTime())
};
}

Expand Down
Loading