Skip to content

Commit

Permalink
[#5550] feat(core): add partition pre event to Gravitino event (#5590)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

1. add corresponding PartitionPreEvent
2. generate pre-event in PartitionEventDispatcher
3. add test in TestPartitionEvent
4. add document in gravitino-server-config.md

### Why are the changes needed?

Fix: #5550

### Does this PR introduce _any_ user-facing change?

NO

### How was this patch tested?

UT
  • Loading branch information
LiuQhahah authored Nov 25, 2024
1 parent dd87cdd commit c1b9885
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@
import org.apache.gravitino.exceptions.PartitionAlreadyExistsException;
import org.apache.gravitino.listener.api.event.AddPartitionEvent;
import org.apache.gravitino.listener.api.event.AddPartitionFailureEvent;
import org.apache.gravitino.listener.api.event.AddPartitionPreEvent;
import org.apache.gravitino.listener.api.event.DropPartitionEvent;
import org.apache.gravitino.listener.api.event.DropPartitionFailureEvent;
import org.apache.gravitino.listener.api.event.DropPartitionPreEvent;
import org.apache.gravitino.listener.api.event.GetPartitionEvent;
import org.apache.gravitino.listener.api.event.GetPartitionFailureEvent;
import org.apache.gravitino.listener.api.event.GetPartitionPreEvent;
import org.apache.gravitino.listener.api.event.ListPartitionEvent;
import org.apache.gravitino.listener.api.event.ListPartitionFailureEvent;
import org.apache.gravitino.listener.api.event.ListPartitionNamesEvent;
import org.apache.gravitino.listener.api.event.ListPartitionNamesFailureEvent;
import org.apache.gravitino.listener.api.event.ListPartitionNamesPreEvent;
import org.apache.gravitino.listener.api.event.ListPartitionPreEvent;
import org.apache.gravitino.listener.api.event.PartitionExistsEvent;
import org.apache.gravitino.listener.api.event.PartitionExistsFailureEvent;
import org.apache.gravitino.listener.api.event.PurgePartitionEvent;
import org.apache.gravitino.listener.api.event.PurgePartitionFailureEvent;
import org.apache.gravitino.listener.api.event.PurgePartitionPreEvent;
import org.apache.gravitino.listener.api.info.partitions.PartitionInfo;
import org.apache.gravitino.rel.partitions.Partition;
import org.apache.gravitino.utils.PrincipalUtils;
Expand Down Expand Up @@ -66,6 +72,9 @@ public PartitionEventDispatcher(EventBus eventBus, PartitionDispatcher dispatche
@Override
public Partition addPartition(NameIdentifier ident, Partition partition)
throws NoSuchPartitionException, PartitionAlreadyExistsException {
eventBus.dispatchEvent(
new AddPartitionPreEvent(
PrincipalUtils.getCurrentUserName(), ident, PartitionInfo.of(partition)));
try {
Partition newPartition = dispatcher.addPartition(ident, partition);
eventBus.dispatchEvent(
Expand All @@ -84,6 +93,8 @@ public Partition addPartition(NameIdentifier ident, Partition partition)
@Override
public Partition getPartition(NameIdentifier ident, String partitionName)
throws NoSuchPartitionException {
eventBus.dispatchEvent(
new GetPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));
try {
Partition partition = dispatcher.getPartition(ident, partitionName);
eventBus.dispatchEvent(
Expand All @@ -100,6 +111,8 @@ public Partition getPartition(NameIdentifier ident, String partitionName)

@Override
public boolean dropPartition(NameIdentifier ident, String partitionName) {
eventBus.dispatchEvent(
new DropPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));
try {
boolean isExists = dispatcher.dropPartition(ident, partitionName);
eventBus.dispatchEvent(
Expand All @@ -116,6 +129,7 @@ public boolean dropPartition(NameIdentifier ident, String partitionName) {

@Override
public Partition[] listPartitions(NameIdentifier ident) {
eventBus.dispatchEvent(new ListPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident));
try {
Partition[] listPartitions = dispatcher.listPartitions(ident);
eventBus.dispatchEvent(new ListPartitionEvent(PrincipalUtils.getCurrentUserName(), ident));
Expand All @@ -129,6 +143,8 @@ public Partition[] listPartitions(NameIdentifier ident) {

@Override
public String[] listPartitionNames(NameIdentifier ident) {
eventBus.dispatchEvent(
new ListPartitionNamesPreEvent(PrincipalUtils.getCurrentUserName(), ident));
try {
String[] listPartitionNames = dispatcher.listPartitionNames(ident);
eventBus.dispatchEvent(
Expand Down Expand Up @@ -159,6 +175,8 @@ public boolean partitionExists(NameIdentifier ident, String partitionName) {

@Override
public boolean purgePartition(NameIdentifier ident, String partitionName) {
eventBus.dispatchEvent(
new PurgePartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));
try {
boolean isExists = dispatcher.purgePartition(ident, partitionName);
eventBus.dispatchEvent(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.listener.api.event;

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
import org.apache.gravitino.listener.api.info.TableInfo;
import org.apache.gravitino.listener.api.info.partitions.PartitionInfo;

/** Represents an event triggered before creating a partition. */
@DeveloperApi
public class AddPartitionPreEvent extends PartitionPreEvent {

private final PartitionInfo createPartitionRequest;

public AddPartitionPreEvent(
String user, NameIdentifier identifier, PartitionInfo createPartitionRequest) {
super(user, identifier);
this.createPartitionRequest = createPartitionRequest;
}

/**
* Retrieves the create partition request.
*
* @return A {@link TableInfo} instance encapsulating the comprehensive details of create
* partition request.
*/
public PartitionInfo createdPartitionRequest() {
return createPartitionRequest;
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.ADD_PARTITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.listener.api.event;

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;

/** Represents an event that is triggered before dropping a partition. */
@DeveloperApi
public class DropPartitionPreEvent extends PartitionPreEvent {
private final String partitionName;

public DropPartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {
super(user, identifier);
this.partitionName = partitionName;
}

public String partitionName() {
return partitionName;
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.DROP_PARTITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.listener.api.event;

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;

/** Represents an event that is triggered before getting a partition. */
@DeveloperApi
public class GetPartitionPreEvent extends PartitionPreEvent {

private final String partitionName;

public GetPartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {
super(user, identifier);
this.partitionName = partitionName;
}

public String partitionName() {
return partitionName;
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.LOAD_PARTITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.listener.api.event;

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;

/** Represents an event that is triggered before listing of partition name within a namespace. */
@DeveloperApi
public class ListPartitionNamesPreEvent extends PartitionPreEvent {

public ListPartitionNamesPreEvent(String user, NameIdentifier identifier) {
super(user, identifier);
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.LIST_PARTITION_NAMES;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.listener.api.event;

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;

/** Represents an event that is triggered before listing of partition within a namespace. */
@DeveloperApi
public class ListPartitionPreEvent extends PartitionPreEvent {

public ListPartitionPreEvent(String user, NameIdentifier identifier) {
super(user, identifier);
}
/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.LIST_PARTITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.listener.api.event;

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;

/** Represents a pre-event for partition operations. */
@DeveloperApi
public abstract class PartitionPreEvent extends PreEvent {

protected PartitionPreEvent(String user, NameIdentifier identifier) {
super(user, identifier);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.listener.api.event;

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;

/** Represents an event triggered before purging a partition. */
@DeveloperApi
public class PurgePartitionPreEvent extends PartitionPreEvent {

private final String partitionName;

public PurgePartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {
super(user, identifier);
this.partitionName = partitionName;
}

public String partitionName() {
return partitionName;
}
/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.PURGE_PARTITION;
}
}
Loading

0 comments on commit c1b9885

Please sign in to comment.