Skip to content

Commit

Permalink
Increase code robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
FLYLX committed Aug 22, 2024
1 parent c2d15dd commit 8c365aa
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 13 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ following the last step.
# define the features for learning
paper_features = [f"feat_{i}" for i in range(128)]

paper_features.append("kcore")
paper_features.append("tc")
paper_features.extend(["kcore", "tc"])

# launch a learning engine.
lg = graphscope.graphlearn(sub_graph, nodes=[("paper", paper_features)],
Expand Down
4 changes: 4 additions & 0 deletions analytical_engine/core/server/command_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ struct CommandDetail {
rpc::QueryArgs query_args;
};

/**
* @brief Implement the serialization and deserialization of CommandDetail
* through grape::InArchive and grape::OutArchive.
*/
grape::InArchive& operator<<(grape::InArchive& in_archive,
const CommandDetail& cd);
grape::OutArchive& operator>>(grape::OutArchive& out_archive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ public class PythonInterpreter {
public PythonInterpreter() {}

public void init() throws IOException {
ProcessBuilder builder = new ProcessBuilder("/usr/bin/env", "python3", "-i");
process = builder.start();
try {
ProcessBuilder builder = new ProcessBuilder("/usr/bin/env", "python3", "-i");
process = builder.start();
logger.info("Process started: {}", process.toString());
} catch (IOException e) {
logger.error("Failed to start process", e);
throw e;
}
outputQueue = new LinkedBlockingQueue<>();
inputQueue = new LinkedBlockingQueue<>();
errorQueue = new LinkedBlockingQueue<>();
Expand Down Expand Up @@ -80,10 +86,11 @@ public String getMatched(String pattern) throws InterruptedException {
while (true) {
str = outputQueue.take();
if (str.contains(pattern)) {
logger.info("Matched pattern: {}", pattern);
return str;
} else {
// logger.info("got cmd output " + str + " but not matched");
logger.info(str);
logger.info("Got cmd output: {}", str);
}
}
}
Expand All @@ -92,8 +99,13 @@ public void close() throws InterruptedException {
is.end();
logger.info("closing input stream thread");
is.interrupt();
os.join();
errorStream.join();
try {
os.join();
errorStream.join();
} catch (InterruptedException e) {
logger.error("Interrupted exception when closing python interpreter", e);
throw e;
}
logger.info("");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ private void initCommunicator(long appAddr)
for (Constructor constructor : constructors) {
if (constructor.getParameterCount() == 1
&& constructor.getParameterTypes()[0].getName().equals("long")) {
communicatorImpl = communicatorClass.cast(constructor.newInstance(appAddr));
logger.info("Init communicator:" + communicatorImpl);
try {
communicatorImpl = communicatorClass.cast(constructor.newInstance(appAddr));
logger.info("Init communicator:" + communicatorImpl);
} catch (Exception e) {
logger.error("Failed to initialize communicator", e);
throw e;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void digestVector(FFIByteVector vector) {
*/
public void reset() {
offset = 0;
readableLimit = vector.size();
}

public void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ public void setRawDouble(long arg0, double arg1) {

public void finishSetting(long offset) {
if (offset > size) {
logger.error("Impossible ");
logger.error(
"Impossible to set size to "
+ offset
+ ", it is larger than the original size "
+ size);
return;
}
nativeResize(this.address, offset);
Expand Down
6 changes: 6 additions & 0 deletions flex/interactive/sdk/python/gs_interactive/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ def get_graph_schema(
self,
graph_id: Annotated[StrictStr, Field(description="The id of graph to get")],
) -> Result[GetGraphSchemaResponse]:
"""Get the schema of a specified graph.
Parameters:
graph_id (str): The ID of the graph whose schema is to be retrieved.
Returns:
Result[GetGraphSchemaResponse]: The result containing the schema of the specified graph.
"""
graph_id = self.ensure_param_str("graph_id", graph_id)
try:
response = self._graph_api.get_schema_with_http_info(graph_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public class GraphAlgoTest {
public static void beforeClass() {
String neo4jServerUrl =
System.getProperty("neo4j.bolt.server.url", "neo4j://localhost:7687");
session = GraphDatabase.driver(neo4jServerUrl).session();
// Ensure that the driver is closed properly
try {
session = GraphDatabase.driver(neo4jServerUrl).session();
} catch (Exception e) {
throw new RuntimeException("Failed to create Neo4j session.", e);
}
}

@Test
Expand Down
5 changes: 5 additions & 0 deletions python/graphscope/gsctl/scripts/format_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ done
GS_SOURCE_DIR="$(dirname -- "$(readlink -f "${BASH_SOURCE}")")"

function format_cpp {
# Check if clang-format is installed
if ! [ -x "$(command -v clang-format)" ]; then
echo 'Downloading clang-format.' >&2
curl -L https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-22538c65/clang-format-8_linux-amd64 --output ${GRAPHSCOPE_HOME}/bin/clang-format
chmod +x ${GRAPHSCOPE_HOME}/clang-format
export PATH="${GRAPHSCOPE_HOME}/bin:${PATH}"
fi
# find all relevant files
pushd "${GS_SOURCE_DIR}"/analytical_engine || exit
files=$(find ./apps ./benchmarks ./core ./frame ./misc ./test \( -name "*.h" -o -name "*.cc" \))

Expand All @@ -47,6 +49,7 @@ function format_cpp {
}

function lint_cpp {
# use cpplint.py for static analysis
pushd "${GS_SOURCE_DIR}"/analytical_engine || exit
files=$(find ./apps ./benchmarks ./core ./frame ./misc ./test \( -name "*.h" -o -name "*.cc" \))

Expand All @@ -65,6 +68,7 @@ function format_java {
}

function format_python {
# Install dependency
if ! [ -x "$(command -v black)" ]; then
pip3 install -r ${GS_SOURCE_DIR}/coordinator/requirements-dev.txt --user
fi
Expand All @@ -81,6 +85,7 @@ function format_python {
}

function format_rust {
# Use cargo fmt for formatting checks
cd "${GS_SOURCE_DIR}"/interactive_engine/executor/assembly/groot
cargo +nightly fmt -- --check
cd "${GS_SOURCE_DIR}"/interactive_engine/executor/assembly/v6d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ install_protobuf() {
workdir=$1
install_prefix=$2

# Check whether protobuf is installed
if [[ -f "${install_prefix}/include/google/protobuf/port.h" ]]; then
log "protobuf already installed, skip."
return 0
fi

# Define the version and download link for protobuf
directory="protobuf-21.9"
file="protobuf-all-21.9.tar.gz"
url="https://github.com/protocolbuffers/protobuf/releases/download/v21.9"
Expand All @@ -295,6 +297,7 @@ install_protobuf() {
download_tar_and_untar_if_not_exists ${directory} ${file} "${url}"
pushd ${directory} || exit

# Configure and compile protobuf
./configure --prefix="${install_prefix}" --enable-shared --disable-static
make -j$(nproc)
make install
Expand All @@ -307,11 +310,13 @@ install_grpc() {
workdir=$1
install_prefix=$2

# Check if grpc is installed
if [[ -f "${install_prefix}/include/grpcpp/grpcpp.h" ]]; then
log "grpc already installed, skip."
return 0
fi

# Define the grpc version and download link
directory="grpc"
branch="v1.49.1"
file="${directory}-${branch}.tar.gz"
Expand All @@ -326,6 +331,7 @@ install_grpc() {
fi
pushd ${directory} || exit

# Configure and compile grpc
cmake . -DCMAKE_INSTALL_PREFIX="${install_prefix}" \
-DCMAKE_PREFIX_PATH="${install_prefix}" \
-DBUILD_SHARED_LIBS=ON \
Expand Down Expand Up @@ -356,24 +362,30 @@ install_patchelf() {
workdir=$1
install_prefix=$2

# Check if patchelf is installed
if [[ -f "${install_prefix}/bin/patchelf" ]]; then
log "patchelf already installed, skip."
return 0
fi

# Define the version and download link for patchelf
ARCH=$(uname -m)

directory="patchelf" # patchelf doesn't have a folder
file="patchelf-0.14.5-${ARCH}.tar.gz"
url="https://github.com/NixOS/patchelf/releases/download/0.14.5"
url=$(maybe_set_to_cn_url ${url})

# Log and start installing patchelf
log "Building and installing ${directory}."
pushd "${workdir}" || exit
mkdir -p "${directory}"
pushd "${directory}" || exit
download_tar_and_untar_if_not_exists ${directory} ${file} "${url}"
mkdir -p ${install_prefix}/bin
mv bin/patchelf ${install_prefix}/bin/patchelf

# Go back to your working directory and clean up your files
popd || exit
popd || exit
cleanup_files "${workdir}/${directory}" "${workdir}/${file}"
Expand All @@ -382,21 +394,24 @@ install_patchelf() {
install_cppkafka() {
workdir=$1
install_prefix=$2

# Check whether cppkafka is installed
if [[ -f "${install_prefix}/include/cppkafka/cppkafka.h" ]]; then
log "cppkafka already installed, skip."
return 0
fi

# Define the cppkafka version and download link
directory="cppkafka-0.4.0"
file="0.4.0.tar.gz"
url="https://graphscope.oss-cn-beijing.aliyuncs.com/dependencies"
url=$(maybe_set_to_cn_url ${url})

# Log and start installing cppkafka
log "Building and installing ${directory}."
pushd "${workdir}" || exit
download_tar_and_untar_if_not_exists ${directory} ${file} "${url}"
pushd ${directory} || exit

# Configure and compile cppkafka
# cppkafka may not find the lib64 directory
export LIBRARY_PATH=${LIBRARY_PATH}:${install_prefix}/lib:${install_prefix}/lib64

Expand All @@ -415,20 +430,25 @@ install_maven() {
workdir=$1
install_prefix=$2

# Check if maven is installed
if [[ -f "${install_prefix}/bin/mvn" ]]; then
log "maven already installed, skip."
return 0
fi

# Define the maven version and download link
directory="apache-maven-3.8.6"
file="apache-maven-3.8.6-bin.tar.gz"
url="https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries"
url=$(maybe_set_to_cn_url ${url})

# Log and start installing maven
log "Building and installing ${directory}."
pushd "${workdir}" || exit
download_tar_and_untar_if_not_exists ${directory} ${file} "${url}"
cp -r ${directory} "${install_prefix}"/

# Configure maven's environment variables
mkdir -p "${install_prefix}"/bin
ln -s "${install_prefix}/${directory}/bin/mvn" "${install_prefix}/bin/mvn"
popd || exit
Expand All @@ -438,8 +458,11 @@ install_maven() {
install_hiactor() {
install_prefix=$1
pushd /tmp

git clone https://github.com/alibaba/hiactor.git -b v0.1.1 --single-branch
cd hiactor && git submodule update --init --recursive

# Configure and compile hiactor
sudo bash ./seastar/seastar/install-dependencies.sh
mkdir build && cd build
cmake -DHiactor_DEMOS=OFF -DHiactor_TESTING=OFF -DHiactor_DPDK=OFF -DCMAKE_INSTALL_PREFIX="${install_prefix}" \
Expand Down
4 changes: 4 additions & 0 deletions python/graphscope/gsctl/scripts/test_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export GS_TEST_DIR=${testdata}

GS_SOURCE_DIR="$(dirname -- "$(readlink -f "${BASH_SOURCE}")")"


function get_test_data {
if [[ ! -d ${GS_TEST_DIR} ]]; then
log "Downloading test data to ${testdata}"
Expand Down Expand Up @@ -141,17 +142,20 @@ function test_learning {

function test_e2e {
get_test_data
# Import python projects in the source directory
cd "${GS_SOURCE_DIR}"/python || exit
if [ "${on_local}" == "True" ]; then
# unittest
python3 -m pytest -s -vvv --exitfirst graphscope/tests/minitest/test_min.py
fi
if [ "${on_k8s}" == "True" ]; then
# Run tests in Kubernetes environment using pytest
python3 -m pytest -s -vvv --exitfirst ./graphscope/tests/kubernetes/test_demo_script.py
fi
}

function test_groot {
# Used to test groot
get_test_data
if [ "${on_local}" == "True" ]; then
info "Testing groot on local"
Expand Down

0 comments on commit 8c365aa

Please sign in to comment.