Skip to content

Conversation

@cmbuhler
Copy link
Owner

No description provided.

@cmbuhler cmbuhler changed the title Persistent logging implementation WIP: Persistent logging Implementation Mar 13, 2020
Copy link

@mpirvu mpirvu left a comment

Choose a reason for hiding this comment

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

I have a few inlined comments on the code.
General observations:

  1. Try to follow our coding conventions regarding placement of curly brackets and indentation
  2. Avoid the use of iostream. Use printf/fprintf instead
  3. If possible, use C strings instead of std::string. If that is not possible we need to find a way to allocate backing memory for those std::string with our region allocators which is freed automatically at the end of a compilation. In general be mindful of where memory is allocated and free it as soon as possible.


class BasePersistentLogger {
protected:
std::string _databaseIP;
Copy link

Choose a reason for hiding this comment

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

These could be marked as const because they are set in the constructor and never changed afterwards



public:
bool connect();
Copy link

Choose a reason for hiding this comment

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

connect, disconnect and logMethod should be marked virtual and override. Not required, but we prefer it that way.


#include <cassandra.h>
#include "BasePersistentLogger.hpp"
class CassandraLogger : public BasePersistentLogger {
Copy link

Choose a reason for hiding this comment

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

Please follow our coding conventions and place the curly bracket on the next line, indented by 3 spaces.

@@ -0,0 +1,200 @@
#include <time.h>
#include <iostream>
Copy link

Choose a reason for hiding this comment

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

Avoid using iostream and use printf style if at all possible.

#include <iostream>

#include "CassandraLogger.hpp"
CassandraLogger::CassandraLogger(std::string const &databaseIP, std::uint32_t databasePort, std::string const &databaseName): BasePersistentLogger(databaseIP, databasePort, databaseName){
Copy link

Choose a reason for hiding this comment

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

Please follow our coding conventions regarding the curly braces

}
#if defined(PERSISTENT_LOGGING_SUPPORT)
//TODO: FIx this flag
//if(TR::Options::getCmdLineOptions()->getOption(TR_PersistLogging))
Copy link

Choose a reason for hiding this comment

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

This option should be used at the client in my opinion. The server should be controlled by those -XX: options. Do we need another option?


class MongoLogger : public BasePersistentLogger {
private:
Omongoc_uri_t *_uri;
Copy link

Choose a reason for hiding this comment

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

These pointers need to be initialized in the constructors.


MongoLogger::~MongoLogger() {
//Clean up this mongoc logger.
Omongoc_collection_destroy(_collection);
Copy link

Choose a reason for hiding this comment

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

Is it safe to destroy NULL pointers?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes it is. The mongoc functions will do nothing if they receive a NULL pointer.

std::cout << "what is the persistent logging database Name ? " << persistentLoggingDatabaseName << std::endl;

#ifdef CASSANDRA_LOGGER
CassandraLogger* logger = new CassandraLogger(persistentLoggingDatabaseAddress, std::persistentLoggingDatabasePort, persistentLoggingDatabaseName,persistentLoggingDatabaseUsername, persistentLoggingDatabasePassword);
Copy link

Choose a reason for hiding this comment

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

A new logger is created dynamically, but who destroys it? If you plan on not reusing it, then allocate it on stack rather than with new.

#endif // CASSANDRA_LOGGER

#ifdef MONGO_LOGGER
MongoLogger* logger = new MongoLogger(persistentLoggingDatabaseAddress, persistentLoggingDatabasePort, persistentLoggingDatabaseName,persistentLoggingDatabaseUsername, persistentLoggingDatabasePassword);
Copy link

Choose a reason for hiding this comment

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

A new logger is created dynamically, but who destroys it? If you plan on not reusing it, then allocate it on stack rather than with new.

@cmbuhler cmbuhler force-pushed the persistent_logging_implementation branch from 4aabc31 to 7243fad Compare March 23, 2020 02:34
@cmbuhler cmbuhler changed the base branch from master to pre_merge March 23, 2020 02:44
@cmbuhler cmbuhler changed the base branch from pre_merge to master March 23, 2020 02:45
@cmbuhler cmbuhler force-pushed the persistent_logging_implementation branch from 7243fad to 565e2e8 Compare March 23, 2020 03:00
Copy link

Choose a reason for hiding this comment

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

This assumes that the strings receives as parameters continue to exist after the object is constructed.
I'll have to verify if that's the case.

Copy link

Choose a reason for hiding this comment

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

Extra space after first (

Copy link

Choose a reason for hiding this comment

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

Let's move this below to the next section protected by #ifdef PERSISTENT_LOGGING_SUPPORT

Copy link

Choose a reason for hiding this comment

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

No iostream please

Copy link

Choose a reason for hiding this comment

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

Extra spaces here

Copy link

Choose a reason for hiding this comment

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

Some alignment issues

Copy link

Choose a reason for hiding this comment

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

If it's statically allocated you don't need allocators.The space is big though, so there is a danger of stack overflow. Maybe reducing that to 256 is sufficient.

Copy link

Choose a reason for hiding this comment

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

This is executed when jitserver boostraps. We need a master option that enables persistent logging at runtime. Getting the option from the client will not do.

Copy link

Choose a reason for hiding this comment

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

maybe we can use some time routines from omr. Do you need the time in a specific format?

Copy link

Choose a reason for hiding this comment

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

Do we need this buffer that big? Only database name is variable, so I am guessing that 256 chars is enough.
Also use snprintf to avoid buffer overflow.

@cmbuhler cmbuhler force-pushed the persistent_logging_implementation branch from 565e2e8 to 54dd396 Compare April 3, 2020 04:55
fixed namespace error

retrieved method signiture

a new way of retrieving method full name

changed to an easier way to retrieve compiled method signature

attempted to add -XX:persistentLoggingDatabasePort flag, hit segmentation fault..

added if clause for persistent logging, retrieved clientUID info

fixed namespace error

retrieved method signiture

Attempt to add logger to openj9.

make Changes and stuff

Add conditionals to check for mongo and cassandra support

-XX flags needed for persistent logging completed

Fix an issue with my previous merge

IMplement environment variable ifdef wrapper thing

port initialization on different DBMS

added if clause for persistent logging, retrieved clientUID info

a new way of retrieving method full name

changed to an easier way to retrieve compiled method signature

attempted to add -XX:persistentLoggingDatabasePort flag, hit segmentation fault..

retrieved method signiture

Attempt to add logger to openj9.

Add conditionals to check for mongo and cassandra support

-XX flags needed for persistent logging completed

IMplement environment variable ifdef wrapper thing

add general persistent logging support flag for checking if persistent logging is enabled regardless of dbms

fix more merge conflicts I forgot

Add more env variable processing

Add fix that allows you to enable the cassandra logger

debug TR_PersistLogging flag

Bring in changes by Ida for persistentLogger spec, dynamically load mongoc library

addressed code review feedback

addressed code review feedback

addressed code review feedback

added if clause for persistent logging, retrieved clientUID info

fixed namespace error

retrieved method signiture

a new way of retrieving method full name

changed to an easier way to retrieve compiled method signature

attempted to add -XX:persistentLoggingDatabasePort flag, hit segmentation fault..

added if clause for persistent logging, retrieved clientUID info

fixed namespace error

retrieved method signiture

Attempt to add logger to openj9.

make Changes and stuff

Add conditionals to check for mongo and cassandra support

-XX flags needed for persistent logging completed

Fix an issue with my previous merge

IMplement environment variable ifdef wrapper thing

port initialization on different DBMS

added if clause for persistent logging, retrieved clientUID info

a new way of retrieving method full name

changed to an easier way to retrieve compiled method signature

attempted to add -XX:persistentLoggingDatabasePort flag, hit segmentation fault..

retrieved method signiture

Attempt to add logger to openj9.

Add conditionals to check for mongo and cassandra support

-XX flags needed for persistent logging completed

IMplement environment variable ifdef wrapper thing

add general persistent logging support flag for checking if persistent logging is enabled regardless of dbms

fix more merge conflicts I forgot

Add more env variable processing

Add fix that allows you to enable the cassandra logger

debug TR_PersistLogging flag

Bring in changes by Ida for persistentLogger spec, dynamically load mongoc library

addressed code review feedback

addressed code review feedback

addressed code review feedback

Begin conversion of mongo to c strings and reformat to code conventions

re-enable flags

Reformat mongologger

addressed code review feedback

addressed code review feedback

addressed code review feedback

Address Feedback. Convert to C Strings. Cleanup Mongoc

Finish making c style changes

Re-add client UID setter and getter in J9PersistentInfo.cpp

Dynamic Load Cassandra

Fist address freedback stuff

made error messages consistent

Convert sprintf to snprintf

Convert sprintf to snprintf

Remove final debug print
@cmbuhler cmbuhler force-pushed the persistent_logging_implementation branch from 54dd396 to 23486ae Compare April 3, 2020 05:05
Copy link

@mpirvu mpirvu left a comment

Choose a reason for hiding this comment

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

I have some more comments on the code

#include "runtime/Listener.hpp"
#endif
#if defined(MONGO_LOGGER)
#include "control/LoadDBLibs.hpp"
Copy link

Choose a reason for hiding this comment

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

Why is "control/LoadDBLibs.hpp" needed? The only thing used in this file is the declaration for JITServer::cleanupMongoC().

int32_t xxJITServerSSLCertArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxJITServerSSLCertOption, 0);
int32_t xxJITServerSSLRootCertsArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxJITServerSSLRootCertsOption, 0);

#if defined(MONGO_LOGGER) || defined(CASSANDRA_LOGGER)
Copy link

Choose a reason for hiding this comment

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

Can we group this big block protected by defined(MONGO_LOGGER) || defined(CASSANDRA_LOGGER) with the next block protected by the same ifdef

Copy link
Collaborator

Choose a reason for hiding this comment

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

fixed

int32_t xxJITServerSSLRootCertsArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxJITServerSSLRootCertsOption, 0);

#if defined(MONGO_LOGGER) || defined(CASSANDRA_LOGGER)
const char *xxJITServerPersistentLoggingOption = "-XX:JITServerPersistentLogging=";
Copy link

Choose a reason for hiding this comment

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

What is the meaning for the values given to this option? It appears to use an integer.
We need some comments here.
If you just wanted to turn the feature on, then we we usually use: -XX:+EnableJITServerPersistentLogging

@@ -0,0 +1,233 @@
//
// Created by cmbuhler on 2020-03-11.
Copy link

Choose a reason for hiding this comment

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

The file needs to have our standard license information

@@ -0,0 +1,248 @@
//
// Created by cmbuhler on 2020-03-11.
Copy link

Choose a reason for hiding this comment

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

All new files need to have our standard license information

// Check if we have the database name
if (strcmp(_databaseName,"") == 0)
{
return "jitserver_logs";
Copy link

Choose a reason for hiding this comment

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

In most cases we write something into _uri_string, but in this case we don't. For uniformity I would copy the database name into the _uri_string buffer.

struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
int64_t timestamp = t.tv_sec * INT64_C(1000) + t.tv_nsec / 1000000;
char clientIDstr[20];
Copy link

Choose a reason for hiding this comment

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

You may need an extra char for the terminating NULL.

@@ -0,0 +1,36 @@
#ifndef MONGOLOGGER_HPP
Copy link

Choose a reason for hiding this comment

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

License information missing

}

#if defined(MONGO_LOGGER) || defined(CASSANDRA_LOGGER)
// TODO: Get Flag from command line.
Copy link

Choose a reason for hiding this comment

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

This TODO has been implemented, hasn't it?

_JITServerPort(38400),
#if defined(MONGO_LOGGER) || defined(CASSANDRA_LOGGER)
_JITServerPersistentLogging(false),
#if defined(CASSANDRA_LOGGER)
Copy link

Choose a reason for hiding this comment

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

In JIT code defines always start at first column

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants